From e5b2f71fcdb4944ba7648aa8fb5bdb7ce3c2a5d4 Mon Sep 17 00:00:00 2001 From: Carl de Billy Date: Mon, 6 Jan 2020 15:36:45 -0500 Subject: [PATCH] Added support for Stelpro Ki & Stelpro Maestro (#2628) * fix potential null exception * Added support for Stelpro Ki * Stelpro Ki: Added support for action_mode (cherry picked from commit 0f740f1aedbedb28d64245531f10a9bfd985e49b) * Stelpro Ki: fix "lock" status update (cherry picked from commit 6ac94411183d92d1f658a7d17a724e50587b8571) * Fixed lint issues * Stelpro: Fixed local_temperature sensor * Added support for Stelpro Maestro * Fix lint * HASS: Fixed support for action_topic/action_template * Prevent a non supported device from causing a null-ref * Update naming. Co-authored-by: Koen Kanters --- lib/extension/deviceConfigure.js | 6 ++++-- lib/extension/homeassistant.js | 37 ++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 2 deletions(-) mode change 100755 => 100644 lib/extension/homeassistant.js diff --git a/lib/extension/deviceConfigure.js b/lib/extension/deviceConfigure.js index 673de256..20988098 100644 --- a/lib/extension/deviceConfigure.js +++ b/lib/extension/deviceConfigure.js @@ -13,11 +13,13 @@ class DeviceConfigure extends BaseExtension { } shouldConfigure(device, mappedDevice) { - if (!device) { + if (!device || !mappedDevice) { return false; } - if (device.meta.hasOwnProperty('configured') && device.meta.configured === mappedDevice.meta.configureKey) { + if (device.meta && + device.meta.hasOwnProperty('configured') && + device.meta.configured === mappedDevice.meta.configureKey) { return false; } diff --git a/lib/extension/homeassistant.js b/lib/extension/homeassistant.js old mode 100755 new mode 100644 index 3c9216fb..aa404679 --- a/lib/extension/homeassistant.js +++ b/lib/extension/homeassistant.js @@ -154,6 +154,15 @@ const cfg = { value_template: '{{ value_json.temperature }}', }, }, + 'sensor_local_temperature': { + type: 'sensor', + object_id: 'local_temperature', + discovery_payload: { + unit_of_measurement: '°C', + device_class: 'temperature', + value_template: '{{ value_json.local_temperature }}', + }, + }, 'sensor_pressure': { type: 'sensor', object_id: 'pressure', @@ -395,6 +404,18 @@ const cfg = { value_template: '{{ value_json.state }}', }, }, + 'lock_keypad_lockout': { + type: 'lock', + object_id: 'keypad_lock', + discovery_payload: { + state_topic: true, + command_topic: true, + command_topic_postfix: 'keypad_lockout', + payload_unlock: '0', + payload_lock: '1', + value_template: '{{ value_json.keypad_lockout }}', + }, + }, // Thermostat/HVAC 'thermostat': (minTemp=7, maxTemp=30, temperatureStateProperty='occupied_heating_setpoint', tempStep=1) => { @@ -415,6 +436,8 @@ const cfg = { temperature_state_template: `{{ value_json.${temperatureStateProperty} }}`, temperature_command_topic: temperatureStateProperty, temp_step: tempStep, + action_topic: true, + action_template: '{{ value_json.operation }}', }, }; }, @@ -1075,6 +1098,16 @@ const mapping = { '067771': [cfg.switch], '064873': [cfg.sensor_action], 'K3004C': [cfg.switch], + 'STZB402': [ + cfg.thermostat(5, 30, 'occupied_heating_setpoint', 0.5), + cfg.sensor_local_temperature, + cfg.lock_keypad_lockout, + ], + 'SMT402': [ + cfg.thermostat(5, 30, 'occupied_heating_setpoint', 0.5), + cfg.sensor_local_temperature, + cfg.lock_keypad_lockout, + ], }; Object.keys(mapping).forEach((key) => { @@ -1239,6 +1272,10 @@ class HomeAssistant extends BaseExtension { payload.speed_command_topic = `${stateTopic}/set/fan_mode`; } + if (payload.action_topic) { + payload.action_topic = stateTopic; + } + // Override configuration with user settings. if (entity.hasOwnProperty('homeassistant')) { const add = (obj) => {