Skip to content
This repository has been archived by the owner on Jun 23, 2022. It is now read-only.

Commit

Permalink
Add support for scripts (#235)
Browse files Browse the repository at this point in the history
* Update multiple files

Add support for scripts (on or on/off, depending on script contents)

* Update README.md

Fix “supported_types” array
  • Loading branch information
schmittx authored and robbiet480 committed Oct 26, 2017
1 parent 43b787f commit 5d3a2d1
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ Here's a list of the devices that are currently exposed:
* **Media Players** - exposed as an on/off switch
* **Remotes** - exposed as an on/off switch
* **Scenes** - exposed as an on/off switch
* **Scripts** - exposed as an on/off switch
* **Sensors** - air quality, carbon dioxide (CO2), humidity, light, temperature sensors
* **Switches** - on/off

Expand Down Expand Up @@ -104,6 +105,12 @@ cannot be deleted. Simply add your Home Assistant scene to them and set the
state you would like them to be when executed. That's most like the ON state.
The switch will automatically turn off shortly after turning on.

### Script Support

Scripts containing only one service call will function exactly like scenes (see above).

Scripts containing more than one service call will be able to be turned off as well.

### Sensor Support

Air quality, carbon dioxide (CO2), humidity, light and temperature sensors are currently supported.
Expand Down Expand Up @@ -141,7 +148,7 @@ To avoid too much information in your log, just set `logging` to `false` as soon
"name": "HomeAssistant",
"host": "http://127.0.0.1:8123",
"password": "yourapipassword",
"supported_types": ["automation", "binary_sensor", "climate", "cover", "device_tracker", "fan", "group", "input_boolean", "light", "lock", "media_player", "remote", "scene", "sensor", "switch"],
"supported_types": ["automation", "binary_sensor", "climate", "cover", "device_tracker", "fan", "group", "input_boolean", "light", "lock", "media_player", "remote", "scene", "script", "sensor", "switch"],
"default_visibility": "hidden",
"logging": true,
"verify_ssl": true
Expand Down
11 changes: 9 additions & 2 deletions accessories/switch.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ HomeAssistantSwitch.prototype = {
this.log(`Setting power state on the '${this.name}' to on`);

this.client.callService(callDomain, 'turn_on', serviceData, (data) => {
if (this.domain === 'scene') {
if (this.domain === 'scene' || (this.domain === 'script' && !(this.data.attributes.can_cancel))) {
setTimeout(() => {
this.service.getCharacteristic(Characteristic.On)
.setValue(false, null, 'internal');
Expand Down Expand Up @@ -138,6 +138,13 @@ HomeAssistantSwitch.prototype = {
model = 'Automation';
}
break;
case 'script':
if (this.data.attributes && this.data.attributes.homebridge_model) {
model = String(this.data.attributes.homebridge_model);
} else {
model = 'Script';
}
break;
default:
model = 'Switch';
}
Expand All @@ -161,7 +168,7 @@ HomeAssistantSwitch.prototype = {
.setCharacteristic(Characteristic.Model, model)
.setCharacteristic(Characteristic.SerialNumber, this.serial);

if (this.domain === 'remote' || this.domain === 'switch' || this.domain === 'input_boolean' || this.domain === 'group' || this.domain === 'automation') {
if (this.domain === 'remote' || this.domain === 'switch' || this.domain === 'input_boolean' || this.domain === 'group' || this.domain === 'automation' || (this.domain === 'script' && this.data.attributes.can_cancel)) {
this.service
.getCharacteristic(Characteristic.On)
.on('get', this.getPowerState.bind(this))
Expand Down
4 changes: 3 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ function HomeAssistantPlatform(log, config, api) {
// auth info
this.host = config.host;
this.password = config.password;
this.supportedTypes = config.supported_types || ['alarm_control_panel', 'automation', 'binary_sensor', 'climate', 'cover', 'device_tracker', 'fan', 'group', 'input_boolean', 'light', 'lock', 'media_player', 'remote', 'scene', 'sensor', 'switch'];
this.supportedTypes = config.supported_types || ['alarm_control_panel', 'automation', 'binary_sensor', 'climate', 'cover', 'device_tracker', 'fan', 'group', 'input_boolean', 'light', 'lock', 'media_player', 'remote', 'scene', 'script', 'sensor', 'switch'];
this.foundAccessories = [];
this.logging = config.logging !== undefined ? config.logging : true;
this.verify_ssl = config.verify_ssl !== undefined ? config.verify_ssl : true;
Expand Down Expand Up @@ -194,6 +194,8 @@ HomeAssistantPlatform.prototype = {
accessory = new HomeAssistantSwitch(that.log, entity, that, 'remote');
} else if (entityType === 'automation') {
accessory = new HomeAssistantSwitch(that.log, entity, that, 'automation');
} else if (entityType === 'script') {
accessory = new HomeAssistantSwitch(that.log, entity, that, 'script');
}
}

Expand Down

0 comments on commit 5d3a2d1

Please sign in to comment.