diff --git a/drivers/SmartThings/zwave-thermostat/fingerprints.yml b/drivers/SmartThings/zwave-thermostat/fingerprints.yml index c8f8a4ef9c..8ec462eef6 100644 --- a/drivers/SmartThings/zwave-thermostat/fingerprints.yml +++ b/drivers/SmartThings/zwave-thermostat/fingerprints.yml @@ -57,7 +57,7 @@ zwaveManufacturer: deviceLabel: Fibaro Thermostat manufacturerId: 0x010F productType: 0x1301 - deviceProfileName: base-radiator-thermostat-10to30C + deviceProfileName: fibaro-heat-controller - id: "0239/0001/0001" deviceLabel: Stelpro Ki Thermostat manufacturerId: 0x0239 diff --git a/drivers/SmartThings/zwave-thermostat/profiles/fibaro-heat-controller.yml b/drivers/SmartThings/zwave-thermostat/profiles/fibaro-heat-controller.yml new file mode 100644 index 0000000000..56603fc1eb --- /dev/null +++ b/drivers/SmartThings/zwave-thermostat/profiles/fibaro-heat-controller.yml @@ -0,0 +1,33 @@ +name: fibaro-heat-controller +components: +- id: main + capabilities: + - id: temperatureMeasurement + version: 1 + - id: thermostatHeatingSetpoint + version: 1 + config: + values: + - key: "heatingSetpoint.value" + range: [ 10, 30 ] + - id: thermostatMode + version: 1 + - id: battery + version: 1 + - id: refresh + version: 1 + categories: + - name: Thermostat +preferences: + - name: "regulatorBehaviour" + title: "Regulator Behaviour" + description: "Change regulator behaviour from Rapid to Moderate" + preferenceType: enumeration + required: true + definition: + options: + 0: "Rapid" + 64: "Moderate" + default: '0' + - preferenceId: tempOffset + explicit: true \ No newline at end of file diff --git a/drivers/SmartThings/zwave-thermostat/profiles/fibaro-heat-extra-sensor.yml b/drivers/SmartThings/zwave-thermostat/profiles/fibaro-heat-extra-sensor.yml index d43154cf67..ea4778e2fd 100644 --- a/drivers/SmartThings/zwave-thermostat/profiles/fibaro-heat-extra-sensor.yml +++ b/drivers/SmartThings/zwave-thermostat/profiles/fibaro-heat-extra-sensor.yml @@ -23,4 +23,17 @@ components: - id: battery version: 1 categories: - - name: GenericSensor \ No newline at end of file + - name: GenericSensor +preferences: + - name: "regulatorBehaviour" + title: "Regulator Behaviour" + description: "Change regulator behaviour from Rapid to Moderate" + preferenceType: enumeration + required: true + definition: + options: + 0: "Rapid" + 64: "Moderate" + default: '0' + - preferenceId: tempOffset + explicit: true \ No newline at end of file diff --git a/drivers/SmartThings/zwave-thermostat/src/fibaro-heat-controller/init.lua b/drivers/SmartThings/zwave-thermostat/src/fibaro-heat-controller/init.lua index be5365edf0..820cf5ba0c 100644 --- a/drivers/SmartThings/zwave-thermostat/src/fibaro-heat-controller/init.lua +++ b/drivers/SmartThings/zwave-thermostat/src/fibaro-heat-controller/init.lua @@ -29,6 +29,7 @@ local Configuration = (require "st.zwave.CommandClass.Configuration")({version=1 local ApplicationStatus = (require "st.zwave.CommandClass.ApplicationStatus")({version=1}) local utils = require "st.utils" +local log = require "log" local FIBARO_HEAT_FINGERPRINTS = { {mfr = 0x010F, prod = 0x1301, model = 0x1000}, -- Fibaro Heat Controller @@ -37,6 +38,8 @@ local FIBARO_HEAT_FINGERPRINTS = { local FORCED_REFRESH_THREAD = "forcedRefreshThread" +local REGULATOR_BEHAVIOUR_DATA = {parameter_number = 2, size = 4, } + local function can_handle_fibaro_heat_controller(opts, driver, device, ...) for _, fingerprint in ipairs(FIBARO_HEAT_FINGERPRINTS) do if device:id_match(fingerprint.mfr, fingerprint.prod, fingerprint.model) then @@ -72,7 +75,7 @@ local function configuration_report_handler(self, device, cmd) device:send_to_component(SensorMultilevel:Get({}), "extraTemperatureSensor") device:send_to_component(Battery:Get({}), "extraTemperatureSensor") elseif (cmd.args.configuration_value == 0 and utils.table_size(device.st_store.profile.components) > 1) then - device:try_update_metadata({profile = "base-radiator-thermostat"}) + device:try_update_metadata({profile = "fibaro-heat-controller"}) end end end @@ -129,6 +132,7 @@ local function do_refresh(self, device) device:send(ThermostatSetpoint:Get({setpoint_type = ThermostatSetpoint.setpoint_type.HEATING_1})) device:send(Battery:Get({})) device:send(Configuration:Get({parameter_number = 3})) + end local function endpoint_to_component(device, endpoint) @@ -147,9 +151,17 @@ local function component_to_endpoint(device, component) end end -local function map_components(self, device) +local function device_init(self, device, args) device:set_endpoint_to_component_fn(endpoint_to_component) device:set_component_to_endpoint_fn(component_to_endpoint) + + if not device.preferences["regulatorBehaviour"] then + if utils.table_size(device.st_store.profile.components) > 1 then + device:try_update_metadata({profile = "fibaro-heat-extra-sensor"}) + else + device:try_update_metadata({profile = "fibaro-heat-controller"}) + end + end end local function device_added(self, device) @@ -163,6 +175,17 @@ local function device_added(self, device) do_refresh(self, device) end +local function info_changed (self, device, event, args) + for name, info in pairs(device.preferences) do + if (device.preferences[name] ~= nil and args.old_st_store.preferences[name] ~= device.preferences[name] ) then + local input = device.preferences[name] + if (name == "regulatorBehaviour") then + device:send(Configuration:Set({ parameter_number = REGULATOR_BEHAVIOUR_DATA.parameter_number, size = REGULATOR_BEHAVIOUR_DATA.size, configuration_value = input })) + end + end + end + end + local fibaro_heat_controller = { NAME = "fibaro heat controller", zwave_handlers = { @@ -187,7 +210,8 @@ local fibaro_heat_controller = { }, lifecycle_handlers = { added = device_added, - init = map_components + init = device_init, + infoChanged = info_changed }, can_handle = can_handle_fibaro_heat_controller } diff --git a/drivers/SmartThings/zwave-thermostat/src/test/test_fibaro_heat_controller.lua b/drivers/SmartThings/zwave-thermostat/src/test/test_fibaro_heat_controller.lua index cac8b883e4..7212f1aeb8 100644 --- a/drivers/SmartThings/zwave-thermostat/src/test/test_fibaro_heat_controller.lua +++ b/drivers/SmartThings/zwave-thermostat/src/test/test_fibaro_heat_controller.lua @@ -38,7 +38,7 @@ local thermostat_endpoints = { local mock_device = test.mock_device.build_test_zwave_device( { - profile = t_utils.get_profile_definition("base-radiator-thermostat.yml"), + profile = t_utils.get_profile_definition("fibaro-heat-controller.yml"), zwave_endpoints = thermostat_endpoints, zwave_manufacturer_id = 0x010F, zwave_product_id = 0x1000, @@ -56,10 +56,23 @@ local mock_device_extended = test.mock_device.build_test_zwave_device( } ) +local mock_device_old_profile = test.mock_device.build_test_zwave_device( + { + profile = t_utils.get_profile_definition("base-radiator-thermostat.yml"), + zwave_endpoints = thermostat_endpoints, + zwave_manufacturer_id = 0x010F, + zwave_product_id = 0x1000, + zwave_product_type = 0x1301, + } +) + local function test_init() test.mock_device.add_test_device(mock_device) test.mock_device.add_test_device(mock_device_extended) + test.mock_device.add_test_device(mock_device_old_profile) + mock_device_old_profile:expect_metadata_update({profile = "fibaro-heat-controller"}) end + test.set_test_init_function(test_init) test.register_message_test( @@ -293,6 +306,24 @@ test.register_message_test( } ) +test.register_coroutine_test( "device should receive changes from regulator behaviour setting change", +function() + test.socket.zwave:__set_channel_ordering("relaxed") + test.socket.device_lifecycle:__queue_receive(mock_device:generate_info_changed( + { + preferences = { + regulatorBehaviour = 64, + } + } + )) + test.socket.zwave:__expect_send( + zw_test_utilities.zwave_test_build_send_command( + mock_device, + Configuration:Set({parameter_number = 2, size = 4, configuration_value = 64}) + ) + ) +end) + test.register_coroutine_test( "Device should be polled after receiving ApplicationBusy command", function()