Skip to content

Commit

Permalink
Merge pull request #56 from rohankapoorcom/lizsugar_automation_domain…
Browse files Browse the repository at this point in the history
…_support

[feat] Automation domain support
  • Loading branch information
rohankapoorcom authored Aug 14, 2023
2 parents 96a83a2 + a410bc6 commit 6353fb6
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 2 deletions.
4 changes: 2 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, lock` entities.
A button card with integrated slider for `automation, light, switch, fan, cover, input_boolean, media_player, climate, lock` entities.

![Preview][preview]
![Preview 2][preview-2]
Expand Down Expand Up @@ -71,7 +71,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, lock` | |
| entity | string | **Required** | HA entity ID from domain `automation, light, switch, fan, cover, input_boolean, media_player, climate, lock` | |
| name | string | **Optional** | Name | `entity.friendly_name` |
| show_attribute | boolean | **Optional** | Show attribute | `false` (except for `media_player` entities) |
| show_name | boolean | **Optional** | Show name | `true` |
Expand Down
35 changes: 35 additions & 0 deletions src/controllers/automation-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 AutomationController 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 ? 'turn_on' : 'turn_off';
this._hass.callService('automation', 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.automation.state._.on');
}
return this._hass.localize('component.automation.state._.off');
}

}
2 changes: 2 additions & 0 deletions src/controllers/get-controller.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { computeDomain } from 'custom-card-helpers';
import { Domain, SliderButtonCardConfig } from '../types';
import { AutomationController } from './automation-controller';
import { ClimateController } from './climate-controller';
import { Controller } from './controller';
import { CoverController } from './cover-controller';
Expand All @@ -17,6 +18,7 @@ export class ControllerFactory {
[Domain.LIGHT]: LightController,
[Domain.FAN]: FanController,
[Domain.SWITCH]: SwitchController,
[Domain.AUTOMATION]: AutomationController,
[Domain.COVER]: CoverController,
[Domain.INPUT_BOOLEAN]: InputBooleanController,
[Domain.MEDIA_PLAYER]: MediaController,
Expand Down
10 changes: 10 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ export enum Domain {
MEDIA_PLAYER = 'media_player',
CLIMATE = 'climate',
LOCK = 'lock',
AUTOMATION = 'automation',
}

export const ActionButtonConfigDefault: ActionButtonConfig = {
Expand Down Expand Up @@ -144,6 +145,15 @@ export const SliderConfigDefaultDomain: Map<string, SliderConfig> = new Map([
force_square: false,
show_attribute: false,
}],
[Domain.AUTOMATION, {
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.COVER, {
direction: SliderDirections.TOP_BOTTOM,
background: SliderBackground.STRIPED,
Expand Down

0 comments on commit 6353fb6

Please sign in to comment.