Skip to content

Commit

Permalink
Added Ikea Styrbar
Browse files Browse the repository at this point in the history
  • Loading branch information
Sian-Lee-SA committed Dec 4, 2022
1 parent 2b7d72b commit 0ab5876
Show file tree
Hide file tree
Showing 13 changed files with 120 additions and 41 deletions.
15 changes: 6 additions & 9 deletions custom_components/switch_manager/assets/switch_manager_panel.js
Original file line number Diff line number Diff line change
Expand Up @@ -502,9 +502,10 @@ function t(t,e,i,s){var o,n=arguments.length,r=n<3?e:null===s?s=Object.getOwnPro
}
h3, #identifier {
padding-left: 25px;
}
#identifier {
position: relative;
}
#identifier-input {
width: 300px;
}
Expand Down Expand Up @@ -681,10 +682,10 @@ function t(t,e,i,s){var o,n=arguments.length,r=n<3?e:null===s?s=Object.getOwnPro
open
hideActions
@closed=${this.closeDialog}
.heading="${$t("Select Blueprint")}">
<p>Can't find a blueprint for your switch? create your own.
<ha-icon-button .path=${"M15.07,11.25L14.17,12.17C13.45,12.89 13,13.5 13,15H11V14.5C11,13.39 11.45,12.39 12.17,11.67L13.41,10.41C13.78,10.05 14,9.55 14,9C14,7.89 13.1,7 12,7A2,2 0 0,0 10,9H8A4,4 0 0,1 12,5A4,4 0 0,1 16,9C16,9.88 15.64,10.67 15.07,11.25M13,19H11V17H13M12,2A10,10 0 0,0 2,12A10,10 0 0,0 12,22A10,10 0 0,0 22,12C22,6.47 17.5,2 12,2Z"} @click=${()=>window.open("https://github.com/Sian-Lee-SA/Home-Assistant-Switch-Manager#blueprints","_blank").focus()}></ha-icon-button>
</p>
.heading=${$t(j`Select Blueprint
<p style="margin: 0;margin-bottom: -16px;font-size: 12px;">Can't find a blueprint for your switch? create your own.
<ha-icon-button style="vertical-align: middle;" .path=${"M15.07,11.25L14.17,12.17C13.45,12.89 13,13.5 13,15H11V14.5C11,13.39 11.45,12.39 12.17,11.67L13.41,10.41C13.78,10.05 14,9.55 14,9C14,7.89 13.1,7 12,7A2,2 0 0,0 10,9H8A4,4 0 0,1 12,5A4,4 0 0,1 16,9C16,9.88 15.64,10.67 15.07,11.25M13,19H11V17H13M12,2A10,10 0 0,0 2,12A10,10 0 0,0 12,22A10,10 0 0,0 22,12C22,6.47 17.5,2 12,2Z"} @click=${()=>window.open("https://github.com/Sian-Lee-SA/Home-Assistant-Switch-Manager#blueprints","_blank").focus()}></ha-icon-button>
</p>`)}>
<mwc-list>
${this._listBlueprints()}
</mwc-list>
Expand All @@ -707,10 +708,6 @@ function t(t,e,i,s){var o,n=arguments.length,r=n<3?e:null===s?s=Object.getOwnPro
h2:first-child {
margin: 0;
}
p {
margin: -35px 0 0 0;
font-size: 0.8em;
}
ha-icon-button {
vertical-align: middle;
}
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
name: Ikea Styrbar
service: Zigbee2MQTT
event_type: mqtt
identifier_key: topic
mqtt_topic_format: zigbee2mqtt/+/action
buttons:
## Not sure why the buttons are back to front and illogical by their numbers??
- x: 247
y: 61
width: 50
shape: circle
actions:
- title: tap
conditions:
- key: payload
value: 'on'
- title: hold
conditions:
- key: payload
value: brightness_move_up
- x: 442
y: 248
width: 50
shape: circle
actions:
- title: tap
conditions:
- key: payload
value: arrow_right_click
- title: hold
conditions:
- key: payload
value: arrow_right_hold
- title: hold (released)
conditions:
- key: payload
value: arrow_right_release
- x: 245
y: 434
width: 50
shape: circle
actions:
- title: tap
conditions:
- key: payload
value: 'off'
- title: hold
conditions:
- key: payload
value: brightness_move_down
- x: 52
y: 248
width: 50
shape: circle
actions:
- title: tap
conditions:
- key: payload
value: arrow_left_click
- title: hold
conditions:
- key: payload
value: arrow_left_hold
- title: hold (released)
conditions:
- key: payload
value: arrow_left_release
2 changes: 1 addition & 1 deletion custom_components/switch_manager/manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"domain": "switch_manager",
"name": "Switch Manager",
"version": "0.1.2",
"version": "0.1.3",
"documentation": "https://github.com/Sian-Lee-SA/switch_manager",
"dependencies": ["panel_custom", "websocket_api", "http", "frontend", "script", "mqtt"],
"requirements": [],
Expand Down
6 changes: 5 additions & 1 deletion js/button-actions.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
import { html, css, LitElement } from "lit";
import { customElement, property, state } from "lit/decorators.js";
import { SwitchManagerBlueprintButtonAction, SwitchManagerConfigButtonAction } from "./types";
import { HomeAssistant } from "@hass/types";

@customElement('switch-manager-button-actions')
class SwitchManagerButtonActions extends LitElement
{
@property() hass!: any;
@property() hass!: HomeAssistant;

@property() blueprint_actions: SwitchManagerBlueprintButtonAction[];

@property() config_actions: SwitchManagerConfigButtonAction[];

@property({reflect: true}) index = 0;

render()
Expand Down
20 changes: 9 additions & 11 deletions js/dialogs/dialog-blueprint-selector.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { html, css, LitElement } from "lit";
import { customElement, property, state } from "lit/decorators.js";
import { SwitchManagerBlueprint } from "../types";
import { HomeAssistant } from "@hass/types";
import {
mdiGestureTapButton,
mdiClose,
Expand All @@ -20,7 +21,8 @@ import { haStyleDialog, haStyleScrollbar } from "@hass/resources/styles"
@customElement('switch-manager-dialog-blueprint-selector')
class SwitchManagerBlueprintSelector extends LitElement
{
@property({attribute: false}) public hass!: any;
@property({attribute: false}) public hass!: HomeAssistant;

@property({attribute: false}) blueprints: {[key: string]: SwitchManagerBlueprint};

@state() private _opened = false;
Expand Down Expand Up @@ -48,10 +50,10 @@ class SwitchManagerBlueprintSelector extends LitElement
open
hideActions
@closed=${this.closeDialog}
.heading="${createCloseHeading('Select Blueprint')}">
<p>Can't find a blueprint for your switch? create your own.
<ha-icon-button .path=${mdiHelpCircle} @click=${() => window.open('https://github.com/Sian-Lee-SA/Home-Assistant-Switch-Manager#blueprints', '_blank').focus()}></ha-icon-button>
</p>
.heading=${createCloseHeading(html`Select Blueprint
<p style="margin: 0;margin-bottom: -16px;font-size: 12px;">Can't find a blueprint for your switch? create your own.
<ha-icon-button style="vertical-align: middle;" .path=${mdiHelpCircle} @click=${() => window.open('https://github.com/Sian-Lee-SA/Home-Assistant-Switch-Manager#blueprints', '_blank').focus()}></ha-icon-button>
</p>`)}>
<mwc-list>
${this._listBlueprints()}
</mwc-list>
Expand Down Expand Up @@ -80,10 +82,6 @@ class SwitchManagerBlueprintSelector extends LitElement
h2:first-child {
margin: 0;
}
p {
margin: -35px 0 0 0;
font-size: 0.8em;
}
ha-icon-button {
vertical-align: middle;
}
Expand Down Expand Up @@ -143,8 +141,8 @@ class SwitchManagerBlueprintSelector extends LitElement

private _updateBlueprints()
{
this.hass.callWS({type: buildWSPath('blueprints')}).then( promise => {
this.blueprints = promise.blueprints;
this.hass.callWS<any>({type: buildWSPath('blueprints')}).then( r => {
this.blueprints = r.blueprints;
}).catch(error => showToast(this, { message: error.message }));
}

Expand Down
3 changes: 2 additions & 1 deletion js/dialogs/dialog-confirm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ import { css, CSSResultGroup, html, LitElement, TemplateResult } from "lit";
import { customElement, property, state } from "lit/decorators.js";
import { classMap } from "lit/directives/class-map.js";
import { ConfirmationDialogParams } from "../helpers";
import { HomeAssistant } from "@hass/types";
import { fireEvent } from "@hass/common/dom/fire_event";

@customElement("switch-manager-dialog-confirm")
class SwitchManagerDialogConfirm extends LitElement
{
@property({ attribute: false }) public hass!: any;
@property({ attribute: false }) public hass!: HomeAssistant;

@state() private _params?: ConfirmationDialogParams;

Expand Down
3 changes: 2 additions & 1 deletion js/dialogs/dialog-rename-switch.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import { css, CSSResultGroup, html, LitElement, TemplateResult } from "lit";
import { customElement, property, state } from "lit/decorators.js";
import { HomeAssistant } from "@hass/types";
import { createCloseHeading } from "../helpers";
import { haStyle, haStyleDialog } from "@hass/resources/styles";
import { fireEvent } from "@hass/common/dom/fire_event";

@customElement('switch-manager-dialog-rename-switch')
class SwitchManagerDialogRenameSwitch extends LitElement
{
@property({ attribute: false }) public hass!: any;
@property({ attribute: false }) public hass!: HomeAssistant;

@state() private _opened = false;

Expand Down
5 changes: 3 additions & 2 deletions js/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { mdiClose } from "@mdi/js";
import { html, LitElement, TemplateResult } from "lit";
import { MODES, ShowToastParams, SwitchManagerBlueprint, SwitchManagerConfig } from "./types";
import { HomeAssistant } from "@hass/types";
import { fireEvent } from "@hass/common/dom/fire_event";

export const DOMAIN = 'switch_manager'

export function computeRTL(hass)
export function computeRTL(hass: HomeAssistant)
{
const lang = hass.language || "en";
if (hass.translationMetadata.translations[lang]) {
Expand All @@ -14,7 +15,7 @@ export function computeRTL(hass)
return false;
}

export function computeRTLDirection(hass)
export function computeRTLDirection(hass: HomeAssistant)
{
return emitRTLDirection(computeRTL(hass));
}
Expand Down
11 changes: 8 additions & 3 deletions js/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { html, css, LitElement } from "lit";
import { customElement, property, state } from "lit/decorators.js";
import { SwitchManagerBlueprint, SwitchManagerConfig } from "./types";
import { HomeAssistant } from "@hass/types";
import memoizeOne from "memoize-one";
import {
mdiPlus,
Expand All @@ -26,10 +27,14 @@ import { fabStyle } from "./styles";
@customElement('switch-manager-index')
class SwitchManagerIndex extends LitElement
{
@property() hass!: any;
@property() hass!: HomeAssistant;

@property() narrow;

@property() panel;

@property() route;

@state() private _data: any[] = [];

private _columns = memoizeOne(
Expand Down Expand Up @@ -177,7 +182,7 @@ class SwitchManagerIndex extends LitElement
private _populateSwitches()
{
const __data = [];
this.hass.callWS({type: buildWSPath('configs')}).then( promise => {
this.hass.callWS<any>({type: buildWSPath('configs')}).then( promise => {
Object.values(promise.configs).forEach( (_switch: SwitchManagerConfig) => {
let blueprint;
if( _switch.valid_blueprint )
Expand Down Expand Up @@ -207,7 +212,7 @@ class SwitchManagerIndex extends LitElement

private async _toggleEnabled( id: string, enabled: boolean )
{
this.hass.callWS({ type: buildWSPath('config/enabled'), enabled: !enabled, config_id: id }).then( r => {
this.hass.callWS<any>({ type: buildWSPath('config/enabled'), enabled: !enabled, config_id: id }).then( r => {
this._populateSwitches();
showToast(this, {
message: `Switch ${r.enabled ? 'Enabled':'Disabled'}`
Expand Down
7 changes: 5 additions & 2 deletions js/main.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
import { customElement, property, state } from "lit/decorators.js";
import { html, LitElement } from "lit";

import { HomeAssistant } from "@hass/types";
import "./index";
import "./switch-editor";
import { loadComponents } from "./helpers";

@customElement('switch-manager-panel')
class SwitchManagerPanel extends LitElement
{
@property() hass!: any;
@property() hass!: HomeAssistant;

@property() narrow;

@property() panel;

@state() params = {};

@state() component_name = "custom";
Expand Down
20 changes: 11 additions & 9 deletions js/switch-editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
} from "@mdi/js";
import { MODES, SwitchManagerBlueprint, SwitchManagerBlueprintCondition, SwitchManagerConfig, SwitchManagerConfigButton } from "./types";
import { haStyle } from "@hass/resources/styles";
import { HomeAssistant } from "@hass/types";
import { subscribeMQTTTopic } from "@hass/data/mqtt";
import {
buildAssetUrl,
Expand All @@ -31,7 +32,7 @@ import "./button-actions";

class SwitchManagerSwitchEditor extends LitElement
{
@property() hass!: any;
@property() hass!: HomeAssistant;
@property() narrow;
@property() panel;
@property() route;
Expand Down Expand Up @@ -255,9 +256,10 @@ class SwitchManagerSwitchEditor extends LitElement
}
h3, #identifier {
padding-left: 25px;
}
#identifier {
position: relative;
}
#identifier-input {
width: 300px;
}
Expand Down Expand Up @@ -382,23 +384,23 @@ class SwitchManagerSwitchEditor extends LitElement
{
if( 'id' in this.params ) {
this.is_new = false;
this.hass.callWS({type: buildWSPath('configs'), config_id: this.params.id}).then( promise => {
this._setConfig(promise.config);
this.hass.callWS<any>({type: buildWSPath('configs'), config_id: this.params.id}).then( r => {
this._setConfig(r.config);
});
} else {
this.is_new = true;
this._dirty = true;
if( 'blueprint' in this.params )
this._loadBlueprint(this.params.blueprint).then( promise => {
this._setConfig( createConfigFromBlueprint(promise.blueprint) );
this._loadBlueprint(this.params.blueprint).then( r => {
this._setConfig( createConfigFromBlueprint(r.blueprint) );
this._showRenameDialog();
});
}
}

private _loadBlueprint(id: string)
{
return this.hass.callWS({type: buildWSPath('blueprints'), blueprint_id: id});
return this.hass.callWS<any>({type: buildWSPath('blueprints'), blueprint_id: id});
}

private _setConfig( config: SwitchManagerConfig )
Expand Down Expand Up @@ -513,7 +515,7 @@ class SwitchManagerSwitchEditor extends LitElement
this._block_save = true;
this._dirty = false;

this.hass.callWS({
this.hass.callWS<any>({
type: buildWSPath('config/save'),
config: {...this.config, blueprint: this.config.blueprint.id}
}).then(r => {
Expand Down Expand Up @@ -673,7 +675,7 @@ class SwitchManagerSwitchEditor extends LitElement
private _toggleEnabled()
{

this.hass.callWS({ type: buildWSPath('config/enabled'), enabled: !this.config.enabled, config_id: this.config.id }).then( r => {
this.hass.callWS<any>({ type: buildWSPath('config/enabled'), enabled: !this.config.enabled, config_id: this.config.id }).then( r => {
this.config.enabled = r.enabled;
this.requestUpdate('config');
showToast(this, { message: `Switch ${r.enabled? 'Enabled':'Disabled'}` });
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "switch_manager",
"private": true,
"version": "0.1.2",
"version": "0.1.3",
"description": "Home Assistant Frontend for Switch Manager",
"scripts": {
"build": "rollup -c",
Expand Down

0 comments on commit 0ab5876

Please sign in to comment.