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

Add support for script domain #11

Open
wants to merge 41 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
8f5701c
Bold the entity name
lizsugar Apr 9, 2022
458d26a
make slider track more pronounced
lizsugar Apr 14, 2022
3a9b803
name and todo updates
lizsugar Apr 14, 2022
2737e93
Change card name to be more obvious
lizsugar Apr 17, 2022
37729ca
Add support for automation domain
lizsugar Apr 17, 2022
3615e5f
source and built files allowing automations as switch cards
lizsugar Apr 18, 2022
746beb5
initial support for relative slider positioning
lizsugar Apr 21, 2022
41a9819
built file with support relative slider positioning
lizsugar Apr 21, 2022
ffb8570
Resolved issue with card bounds cutting off relative slider movement
lizsugar Apr 21, 2022
1ecdb3e
Add support for automation domain
lizsugar Apr 17, 2022
ce8d556
source and built files allowing automations as switch cards
lizsugar Apr 18, 2022
cf160ef
initial support for relative slider positioning
lizsugar Apr 21, 2022
1244ea4
built file with support relative slider positioning
lizsugar Apr 21, 2022
25659c8
Resolved issue with card bounds cutting off relative slider movement
lizsugar Apr 21, 2022
5ff5b1f
Initial yaml config and handling for tap_action on slider
lizsugar Apr 21, 2022
a9c6fb7
Change how I'm handling the slider tap action
lizsugar Apr 22, 2022
b9dbd83
create proper automation controller
lizsugar Apr 22, 2022
1c5c315
initial attribute yaml config
lizsugar Apr 23, 2022
0755edb
Resolve "semantic error TS2515: Non-abstract class '__' does not impl…
lizsugar Apr 25, 2022
b9b7aea
Merge branch 'relative_slider_positioning' into main
lizsugar Apr 25, 2022
88e3567
Merge branch 'automation_domain_support' into main
lizsugar Apr 25, 2022
fadd518
Merge pull request #2 from rohankapoorcom/animate-speedless-fans-upst…
lizsugar Apr 25, 2022
1af7253
create dist file after latest merges
lizsugar Apr 25, 2022
12246fd
Display user-defined attribute
lizsugar Apr 26, 2022
89bf928
minor visual changes and default attribute options by domain
lizsugar Apr 26, 2022
db64daa
Merge branch 'visual_changes' into main
lizsugar Apr 26, 2022
5005eb7
fork specific readme updates
lizsugar Apr 26, 2022
57817d5
initial controller for input-number domain
lizsugar Apr 26, 2022
3a6f885
Add input_number domain to slider-button-card
lizsugar Apr 27, 2022
528b672
Merge branch 'input_number' into main
lizsugar Apr 27, 2022
80355ec
resolve issue with sliders that are not 0 to 100
lizsugar Apr 27, 2022
bc7c570
Merge branch 'relative_slider_positioning' into main
lizsugar Apr 27, 2022
c068172
State and attribute are now displyed on a single line
lizsugar Apr 29, 2022
dea525d
Merge branch 'visual_changes' into main
lizsugar Apr 29, 2022
a2bbbbc
build after merge
lizsugar Apr 29, 2022
83590d9
Added en language/gui toggle for slider tap_action
lizsugar Apr 29, 2022
e69ace2
Merge branch 'slider_tap_action' into main
lizsugar Apr 30, 2022
4c1c701
Add support for sensor domain and binary_sensor domain
lizsugar May 3, 2022
c8b86d7
Merge branch 'sensor_cards' into main
lizsugar May 3, 2022
7f3e715
fix missing configs on BINARY_SENSOR and SENSOR
lizsugar May 6, 2022
8c57bf8
initial script domain support
lizsugar May 13, 2022
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
7,573 changes: 7,434 additions & 139 deletions dist/slider-button-card.js

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions src/controllers/automation-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ export class AutomationController extends Controller {
_max = 1;
_targetValue;
_invert = false;
_clickPosition;
_clickPositionLock;
_originalValue;
_originalValueLock;

get _value(): number {
return !STATES_OFF.includes(this.stateObj.state)
Expand Down
7 changes: 7 additions & 0 deletions src/controllers/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,13 @@ export abstract class Controller {
return `${this.targetValue}`;
}

get attributeLabel(): string {
if (this._config.attribute) {
return this.stateObj.attributes[this._config.attribute];
}
return '';
}

get hidden(): boolean {
return false;
}
Expand Down
22 changes: 22 additions & 0 deletions src/editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ export class SliderButtonCardEditor extends LitElement implements LovelaceCardEd
return typeof this._config?.show_state === 'undefined' ? true : this._config?.show_state;
}

get _show_attribute(): boolean {
return typeof this._config?.show_attribute === 'undefined' ? true : this._config?.show_attribute;
}

get _compact(): boolean {
return typeof this._config?.compact !== 'boolean' ? false : this._config?.compact;
}
Expand All @@ -70,6 +74,10 @@ export class SliderButtonCardEditor extends LitElement implements LovelaceCardEd
return this._config?.entity || '';
}

get _attribute(): string {
return this._config?.attribute || '';
}

get _icon(): IconConfig {
return this._config?.icon || IconConfigDefault;
}
Expand Down Expand Up @@ -112,6 +120,13 @@ export class SliderButtonCardEditor extends LitElement implements LovelaceCardEd
.configValue=${'name'}
@value-changed=${this._valueChanged}
></paper-input>
<paper-input
label="${localize('tabs.general.attribute')}"
.value=${this._attribute}
.placeholder=""
.configValue=${'attribute'}
@value-changed=${this._valueChanged}
></paper-input>
<div class="side-by-side">
<ha-formfield .label=${localize('tabs.general.show_name')}>
<ha-switch
Expand All @@ -127,6 +142,13 @@ export class SliderButtonCardEditor extends LitElement implements LovelaceCardEd
@change=${this._valueChanged}
></ha-switch>
</ha-formfield>
<ha-formfield .label=${localize('tabs.general.show_attribute')}>
<ha-switch
.checked=${this._show_attribute}
.configValue=${'show_attribute'}
@change=${this._valueChanged}
></ha-switch>
</ha-formfield>
<ha-formfield .label=${localize('tabs.general.compact')}>
<ha-switch
.checked=${this._compact}
Expand Down
2 changes: 2 additions & 0 deletions src/localize/languages/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@
"general": {
"title": "General",
"entity": "Entity (Required)",
"attribute": "Attribute (Optional)",
"name": "Name (Optional)",
"show_name": "Show name?",
"show_state": "Show state?",
"show_attribute": "Show attribute?",
"compact": "Compact?"
},
"icon": {
Expand Down
45 changes: 33 additions & 12 deletions src/slider-button-card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ export class SliderButtonCard extends LitElement implements LovelaceCard {
}

private renderText(): TemplateResult {
if (!this.config.show_name && !this.config.show_state) {
if (!this.config.show_name && !this.config.show_state && !this.config.show_attribute) {
return html``;
}
return html`
Expand All @@ -189,17 +189,29 @@ export class SliderButtonCard extends LitElement implements LovelaceCard {
? html`
<div class="name">${this.ctrl.name}</div>
`
: ''}
${this.config.show_state
? html`
<div class="state">
${this.ctrl.isUnavailable
? html`
${this.hass.localize('state.default.unavailable')}
` : html`
${this.ctrl.label}
`}
</div>
: ''}

${this.config.show_state
? html`
<span class="state">
${this.ctrl.isUnavailable
? html`
${this.hass.localize('state.default.unavailable')}
` : html`
${this.ctrl.label}
`}
</span>
`
: ''}

${this.config.show_attribute
? html`
<span class="attribute">
${this.config.show_state && this.ctrl.attributeLabel
? html ` · `
: ''}
${this.ctrl.attributeLabel}
</span>
`
: ''}
</div>
Expand Down Expand Up @@ -615,6 +627,15 @@ export class SliderButtonCard extends LitElement implements LovelaceCard {
overflow: hidden;
}

/* --- ATTRIBUTE --- */

.attribute {
color: var(--state-color-on, var(--label-badge-text-color, white));
text-overflow: ellipsis;
white-space: nowrap;
text-shadow: var(--state-text-shadow);
transition: font-size 0.1s ease-in-out;
}

/* --- SLIDER --- */

Expand Down
11 changes: 11 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@ declare global {
export interface SliderButtonCardConfig extends LovelaceCardConfig {
type: string;
entity: string;
attribute?: string;
name?: string;
show_name?: boolean;
show_state?: boolean;
show_attribute?: boolean;
icon?: IconConfig;
action_button?: ActionButtonConfig;
slider?: SliderConfig;
Expand Down Expand Up @@ -120,6 +122,7 @@ export const SliderConfigDefaultDomain: Map<string, SliderConfig> = new Map([
show_track: false,
toggle_on_click: false,
force_square: false,
show_attribute: false,
}],
[Domain.FAN, {
direction: SliderDirections.LEFT_RIGHT,
Expand All @@ -129,6 +132,7 @@ export const SliderConfigDefaultDomain: Map<string, SliderConfig> = new Map([
show_track: false,
toggle_on_click: false,
force_square: false,
show_attribute: false,
}],
[Domain.SWITCH, {
direction: SliderDirections.LEFT_RIGHT,
Expand All @@ -138,6 +142,7 @@ export const SliderConfigDefaultDomain: Map<string, SliderConfig> = new Map([
show_track: false,
toggle_on_click: true,
force_square: false,
show_attribute: false,
}],
[Domain.AUTOMATION, {
direction: SliderDirections.LEFT_RIGHT,
Expand All @@ -157,6 +162,7 @@ export const SliderConfigDefaultDomain: Map<string, SliderConfig> = new Map([
show_track: false,
force_square: false,
invert: true,
show_attribute: false,
}],
[Domain.INPUT_BOOLEAN, {
direction: SliderDirections.LEFT_RIGHT,
Expand All @@ -166,6 +172,7 @@ export const SliderConfigDefaultDomain: Map<string, SliderConfig> = new Map([
show_track: false,
toggle_on_click: true,
force_square: false,
show_attribute: false,
}],
[Domain.MEDIA_PLAYER, {
direction: SliderDirections.LEFT_RIGHT,
Expand All @@ -175,6 +182,8 @@ export const SliderConfigDefaultDomain: Map<string, SliderConfig> = new Map([
show_track: true,
toggle_on_click: false,
force_square: false,
show_attribute: true,
attribute: "media_title",
}],
[Domain.LOCK, {
direction: SliderDirections.LEFT_RIGHT,
Expand All @@ -184,6 +193,7 @@ export const SliderConfigDefaultDomain: Map<string, SliderConfig> = new Map([
show_track: false,
toggle_on_click: true,
force_square: false,
show_attribute: false,
}],
[Domain.CLIMATE, {
direction: SliderDirections.LEFT_RIGHT,
Expand All @@ -193,6 +203,7 @@ export const SliderConfigDefaultDomain: Map<string, SliderConfig> = new Map([
show_track: true,
toggle_on_click: false,
force_square: false,
show_attribute: false,
}],
]);

Expand Down