Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(entities): added a switch entity
Allows integrations to register switches that can be turned on or off from the home automation software.
- Loading branch information
Showing
5 changed files
with
172 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { Entity } from './entity'; | ||
|
||
export class Switch extends Entity { | ||
state: boolean; | ||
|
||
turnOn(): void { | ||
this.state = true; | ||
} | ||
|
||
turnOff(): void { | ||
this.state = false; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { EntityConfig } from './entity-config'; | ||
|
||
export class SwitchConfig extends EntityConfig { | ||
readonly payloadOn = 'on'; | ||
readonly payloadOff = 'off'; | ||
readonly stateOn = 'true'; | ||
readonly stateOff = 'false'; | ||
icon?: string; | ||
commandTopic: string; | ||
commandStore: { [key in 'on' | 'off']: () => undefined }; | ||
|
||
constructor( | ||
id: string, | ||
name: string, | ||
onCallback?: () => undefined, | ||
offCallback?: () => undefined | ||
) { | ||
super('switch', id, name); | ||
this.commandTopic = `room-assistant/${this.component}/${id}/command`; | ||
this.commandStore = { | ||
on: onCallback, | ||
off: offCallback | ||
}; | ||
} | ||
} |