Skip to content

Commit

Permalink
Merge pull request #36 from mattieha/feat/lock-domain
Browse files Browse the repository at this point in the history
feat: add support for lock entities
  • Loading branch information
mattieha authored Jul 2, 2021
2 parents a72c4bc + 5b7ab93 commit a5f63f1
Show file tree
Hide file tree
Showing 6 changed files with 121 additions and 41 deletions.
37 changes: 35 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
[![GitHub Release][releases-shield]][releases]
[![hacs_badge](https://img.shields.io/badge/HACS-default-orange.svg?style=for-the-badge)](https://github.com/custom-components/hacs)

A button card with integrated slider for `light, switch, fan, cover, input_boolean, media_player, climate` entities.
A button card with integrated slider for `light, switch, fan, cover, input_boolean, media_player, climate, lock` entities.

![Preview][preview]

Expand Down Expand Up @@ -33,6 +33,7 @@ A button card with integrated slider for `light, switch, fan, cover, input_boole
- [Cover](#cover)
- [Media player](#media-player)
- [Climate](#climate)
- [Lock](#lock)
- [In a grid](#grid)
- [Known issues](#known-issues)
- [Languages](#languages)
Expand Down Expand Up @@ -68,7 +69,7 @@ Slider Button Card supports Lovelace's Visual Editor.
| Name | Type | Requirement | Description | Default |
| ----------------- | ------- | ------------ | ------------------------------------------- | ------------------- |
| type | string | **Required** | `custom:slider-button-card` |
| entity | string | **Required** | HA entity ID from domain `light, switch, fan, cover, input_boolean, media_player, climate` | |
| entity | string | **Required** | HA entity ID from domain `light, switch, fan, cover, input_boolean, media_player, climate, lock` | |
| name | string | **Optional** | Name | `entity.friendly_name` |
| show_name | boolean | **Optional** | Show name | `true` |
| show_state | boolean | **Optional** | Show state | `true` |
Expand Down Expand Up @@ -587,6 +588,38 @@ name: Airco
</tr>
</table>

#### Lock
Default behavior: `slider.toggle_on_click: true`
<table>
<tr>
<td></td>
<td>Action button hidden
</td>
</tr>
<tr>
<td><img src="https://raw.githubusercontent.com/mattieha/slider-button-card/main/assets/examples/lock.gif">
</td>
<td valign="top">

```yaml
type: custom:slider-button-card
entity: lock.virtual_lock
slider:
direction: left-right
background: solid
toggle_on_click: true
icon:
use_state_color: true
tap_action:
action: more-info
action_button:
show: false
name: Lock
```
</td>
</tr>
</table>

#### Grid

<table>
Expand Down
Binary file added assets/examples/lock.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
78 changes: 39 additions & 39 deletions dist/slider-button-card.js

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions src/controllers/get-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { CoverController } from './cover-controller';
import { FanController } from './fan-controller';
import { InputBooleanController } from './input-boolean-controller';
import { LightController } from './light-controller';
import { LockController } from './lock-controller';
import { MediaController } from './media-controller';
import { SwitchController } from './switch-controller';

Expand All @@ -20,6 +21,7 @@ export class ControllerFactory {
[Domain.INPUT_BOOLEAN]: InputBooleanController,
[Domain.MEDIA_PLAYER]: MediaController,
[Domain.CLIMATE]: ClimateController,
[Domain.LOCK]: LockController,
};
if (typeof mapping[domain] === 'undefined') {
throw new Error(`Unsupported entity type: ${domain}`)
Expand Down
35 changes: 35 additions & 0 deletions src/controllers/lock-controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { STATES_OFF } from 'custom-card-helpers';
import { Controller } from './controller';

export class LockController extends Controller {
_min = 0;
_max = 1;
_targetValue;
_invert = false;

get _value(): number {
return !STATES_OFF.includes(this.stateObj.state)
? 1
: 0;
}

set _value(value) {
const service = value > 0 ? 'lock' : 'unlock';
this._hass.callService('lock', service, {
// eslint-disable-next-line @typescript-eslint/camelcase
entity_id: this.stateObj.entity_id
});
}

get _step(): number {
return 1;
}

get label(): string {
if (this.percentage > 0) {
return this._hass.localize('component.lock.state._.unlocked');
}
return this._hass.localize('component.lock.state._.locked');
}

}
10 changes: 10 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ export enum Domain {
INPUT_BOOLEAN = 'input_boolean',
MEDIA_PLAYER = 'media_player',
CLIMATE = 'climate',
LOCK = 'lock',
}

export const ActionButtonConfigDefault: ActionButtonConfig = {
Expand Down Expand Up @@ -165,6 +166,15 @@ export const SliderConfigDefaultDomain: Map<string, SliderConfig> = new Map([
toggle_on_click: false,
force_square: false,
}],
[Domain.LOCK, {
direction: SliderDirections.LEFT_RIGHT,
background: SliderBackground.SOLID,
use_state_color: false,
use_percentage_bg_opacity: false,
show_track: false,
toggle_on_click: true,
force_square: false,
}],
[Domain.CLIMATE, {
direction: SliderDirections.LEFT_RIGHT,
background: SliderBackground.TRIANGLE,
Expand Down

0 comments on commit a5f63f1

Please sign in to comment.