Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feat] Automation domain support #56

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -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]
@@ -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` |
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';
@@ -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,
10 changes: 10 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
@@ -83,6 +83,7 @@ export enum Domain {
MEDIA_PLAYER = 'media_player',
CLIMATE = 'climate',
LOCK = 'lock',
AUTOMATION = 'automation',
}

export const ActionButtonConfigDefault: ActionButtonConfig = {
@@ -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,