diff --git a/CHANGELOG.md b/CHANGELOG.md index a5562e50..26e1ddd2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,29 @@ # Change Log +## [0.7.4](https://github.com/jshessen/SmartThingsEdgeDrivers/compare/v0.7.3...v0.7.4) (2023-02-20) + + +### :scissors: Code Refactoring + +* **color:** extended set_switch_color ([1033c8a](https://github.com/jshessen/SmartThingsEdgeDrivers/commit/1033c8a6aef27accdd2d681f4be9ec1a2ede1b11)) +* **hsm200:** Change category type ([db9fe7b](https://github.com/jshessen/SmartThingsEdgeDrivers/commit/db9fe7b2241013e7414ef9df26349aa7220dbd77)) +* **hsm200:** ensure parity w/ ezmultipli ([1080f94](https://github.com/jshessen/SmartThingsEdgeDrivers/commit/1080f941f91d22dfe67b66c872f65ef5193193eb)) +* **hsm200:** remove debug/trace statements ([90c8feb](https://github.com/jshessen/SmartThingsEdgeDrivers/commit/90c8febbcecf3d49a9278ac999fab297c093ac84)) + + +### :hammer_and_wrench: Bug Fixes + +* **helpers:** Fix helper path locations ([f19f475](https://github.com/jshessen/SmartThingsEdgeDrivers/commit/f19f4757735643f4bdc1d743acc231c4a4b1ba30)) +* **hsm200:** Add SwitchMultiLevel.Report handler ([4c99410](https://github.com/jshessen/SmartThingsEdgeDrivers/commit/4c99410b2835b53f9b27f01f0a59f2f8aa463de5)) +* **hsm200:** Convert dim duration to number ([b016488](https://github.com/jshessen/SmartThingsEdgeDrivers/commit/b0164882cc61485e3d8e1e5503a9db000b423055)) +* **hsm200:** eliminate the micro-second math ([b174af3](https://github.com/jshessen/SmartThingsEdgeDrivers/commit/b174af35ee3f5cf23da04676e86fdf9bd80ead7e)) +* **switch:** remote switch response ([5cd854d](https://github.com/jshessen/SmartThingsEdgeDrivers/commit/5cd854da243bf9352a93cf6f10e98312f0043f02)) + + +### :broom: Miscellaneous Chores + +* **sensor:** add reference ezmultipli lua ([ac3d65a](https://github.com/jshessen/SmartThingsEdgeDrivers/commit/ac3d65a6531efb1cf489919516e29a2d8988bac0)) + ## [0.7.4-beta.1](https://github.com/jshessen/SmartThingsEdgeDrivers/compare/v0.7.3...v0.7.4-beta.1) (2023-02-20) diff --git a/drivers/SmartThings/zwave-sensor/profiles/homeseer-hsm200.yaml b/drivers/SmartThings/zwave-sensor/profiles/homeseer-hsm200.yaml index 297fcb90..88330c07 100644 --- a/drivers/SmartThings/zwave-sensor/profiles/homeseer-hsm200.yaml +++ b/drivers/SmartThings/zwave-sensor/profiles/homeseer-hsm200.yaml @@ -24,7 +24,7 @@ components: - id: refresh version: 1 categories: - - name: MultiFunctionalSensor + - name: MotionSensor preferences: - name: "motionDelayTime" title: "Motion Sensor Delay Time" diff --git a/drivers/SmartThings/zwave-sensor/src/homeseer-hsm200-sensor/init.lua b/drivers/SmartThings/zwave-sensor/src/homeseer-hsm200-sensor/init.lua index f28c1f83..a10eeefb 100644 --- a/drivers/SmartThings/zwave-sensor/src/homeseer-hsm200-sensor/init.lua +++ b/drivers/SmartThings/zwave-sensor/src/homeseer-hsm200-sensor/init.lua @@ -82,24 +82,36 @@ local capability_handlers = {} --- @param device (st.zwave.Device) The device instance. --- @param command (Command) The command table. function zwave_handlers.switch_multilevel_handler(driver, device, command) - -- Declare local variables 'level' and 'value' - local level = command.args.value or command.args.target_value -- Simplify if-else statement + -- Declare local variables + local event + local level = command.args.target_value or command.args.value local value = (level > 0 or level == SwitchBinary.value.ON_ENABLE) and SwitchBinary.value.ON_ENABLE or SwitchBinary.value.OFF_DISABLE + local endpoint = command.src_channel + log.debug(string.format("***** HSM200 *****: switch_multilevel_handler, In function")) if command.component == "main" then + log.debug(string.format("***** HSM200 *****: switch_multilevel_handler, In \"main\" conditional")) + if value == SwitchBinary.value.OFF_DISABLE then + log.debug(string.format("***** HSM200 *****: switch_multilevel_handler, In \"off\"")) + event = capabilities.switch.switch.off() + log.debug(string.format("***** HSM200 *****: switch_multilevel_handler, emit hue=0")) + device:emit_event_for_endpoint(endpoint, capabilities.colorControl.hue(0)) + log.debug(string.format("***** HSM200 *****: switch_multilevel_handler, emit saturation=0")) + device:emit_event_for_endpoint(endpoint, capabilities.colorControl.saturation(0)) + else + log.debug(string.format("***** HSM200 *****: switch_multilevel_handler, In \"on\"")) + event = capabilities.switch.switch.on() + end --local set = SwitchBinary:Set({ target_value=value, duration=0 }) + log.debug(string.format("***** HSM200 *****: switch_multilevel_handler, Basic:Set")) local set = Basic:Set({ value=value }) device:send(set) - if value == SwitchBinary.value.ON_ENABLE then - device:emit_event(capabilities.switch.switch.on()) - else - device:emit_event(capabilities.switch.switch.off()) - local hue=capabilities.colorControl.hue(0) - local saturation=capabilities.colorControl.saturation(0) - device:emit_event_for_endpoint(command.src_channel,hue,saturation) - end + log.debug(string.format("***** HSM200 *****: switch_multilevel_handler, emit on/off event")) + device:emit_event_for_endpoint(endpoint, event) + if device:supports_capability(capabilities.switchLevel, nil) then + log.debug(string.format("***** HSM200 *****: switch_multilevel_handler, In switchLevel conditional")) local dimmingDuration = command.args.rate or constants.DEFAULT_DIMMING_DURATION level = math.floor(level + 0.5) -- Round off 'level' to the nearest integer level = utils.clamp_value(level, 0, 99) -- Clamp 'level' to the range [0, 99] @@ -123,20 +135,26 @@ function zwave_handlers.switch_color_handler(driver, device, command) local color = helpers.color.map[7] local hue local saturation + + log.debug(string.format("***** HSM200 *****: switch_color_handler, In function")) if command.args.color then hue = command.args.color.hue + log.debug(string.format("***** HSM200 *****: switch_color_handler, hue=%s",hue)) saturation = command.args.color.saturation + log.debug(string.format("***** HSM200 *****: switch_color_handler, saturation=%s",saturation)) --log.trace(string.format("%s: basic_report_handler -- Find the closest supported color", device:pretty_print())) --color = helpers.color.find_closest_color(hue, saturation, nil) end --local r, g, b = helpers.color.hex_to_rgb(color.hex) local r, g, b = utils.hsl_to_rgb(hue,saturation,nil) + log.debug(string.format("***** HSM200 *****: switch_color_handler, HSL to RGB, r=%s,g=%s,b=%s",r,g,b)) if not r then log.error(string.format("%s: Failed to convert color Hue/Saturation to RGB.", device:pretty_print())) return end + log.debug(string.format("***** HSM200 *****: switch_color_handler,call set_switch_color")) helpers.color.set_switch_color(device, command, r, g, b) end capability_handlers.switch_color_handler = zwave_handlers.switch_color_handler @@ -175,14 +193,17 @@ end --- @param value (st.zwave.CommandClass.SwitchBinary.value) --- @return (function) function capability_handlers.switch_binary_handler(value) - --- Hand off to zwave_handlers.switch_multilevel_handler - --- @param driver (Driver) The driver object - --- @param device (st.zwave.Device) The device object - --- @param command (Command) Input command value - --- @return (nil) + log.debug(string.format("***** HSM200 *****: switch_binary_handler, In function")) + --- Hand off to zwave_handlers.switch_multilevel_handler + --- @param driver (Driver) The driver object + --- @param device (st.zwave.Device) The device object + --- @param command (Command) Input command value + --- @return (nil) return function(driver, device, command) + log.debug(string.format("***** HSM200 *****: switch_bianry_handler, value=%s",value)) command.args.value = value - zwave_handlers.switch_multilevel_handler(device,device,command) + log.debug(string.format("***** HSM200 *****: switch_binary_handler, call switch_multilevel_handler")) + zwave_handlers.switch_multilevel_handler(driver,device,command) end end @@ -194,9 +215,9 @@ local homeseer_multipurpose_sensor = { [cc.BASIC] = { [Basic.REPORT] = zwave_handlers.switch_multilevel_handler }, - --[cc.NOTIFICATIONS] = { - --[Notification.REPORT] = zwave_handlers.notification_report_handler - --} + --[[ [cc.NOTIFICATION] = { + [Notification.REPORT] = zwave_handlers.notification_report_handler + } ]] }, capability_handlers = { [capabilities.switch.ID] = { diff --git a/drivers/SmartThings/zwave-switch/profiles/homeseer-wx300s-status-latest.yaml b/drivers/SmartThings/zwave-switch/profiles/homeseer-wx300s-status-latest.yaml index 01db9960..2c340777 100644 --- a/drivers/SmartThings/zwave-switch/profiles/homeseer-wx300s-status-latest.yaml +++ b/drivers/SmartThings/zwave-switch/profiles/homeseer-wx300s-status-latest.yaml @@ -12,7 +12,7 @@ components: - id: refresh version: 1 categories: - - name: Switch + - name: Light - id: LED-1 capabilities: - id: switch @@ -20,7 +20,7 @@ components: - id: colorControl version: 1 categories: - - name: Switch + - name: Light - id: LED-2 capabilities: - id: switch @@ -28,7 +28,7 @@ components: - id: colorControl version: 1 categories: - - name: Switch + - name: Light - id: LED-3 capabilities: - id: switch @@ -36,7 +36,7 @@ components: - id: colorControl version: 1 categories: - - name: Switch + - name: Light - id: LED-4 capabilities: - id: switch @@ -44,7 +44,7 @@ components: - id: colorControl version: 1 categories: - - name: Switch + - name: Light - id: LED-5 capabilities: - id: switch @@ -52,7 +52,7 @@ components: - id: colorControl version: 1 categories: - - name: Switch + - name: Light - id: LED-6 capabilities: - id: switch @@ -60,7 +60,7 @@ components: - id: colorControl version: 1 categories: - - name: Switch + - name: Light - id: LED-7 capabilities: - id: switch @@ -68,7 +68,7 @@ components: - id: colorControl version: 1 categories: - - name: Switch + - name: Light preferences: - name: "operatingMode" title: "Switch Operating Mode" @@ -128,7 +128,7 @@ preferences: 6: "Cyan" default: 0 - name: "ledStatusBlink1" - title: "LED-1 Enable Status Blink" + title: "LED-1 Enable Blink Functionality" description: "Default: Off" required: false preferenceType: boolean @@ -151,7 +151,7 @@ preferences: 6: "Cyan" default: 0 - name: "ledStatusBlink2" - title: "LED-2 Enable Status Blink" + title: "LED-2 Enable Blink Functionality" description: "Default: Off" required: false preferenceType: boolean @@ -174,7 +174,7 @@ preferences: 6: "Cyan" default: 0 - name: "ledStatusBlink3" - title: "LED-3 Enable Status Blink" + title: "LED-3 Enable Blink Functionality" description: "Default: Off" required: false preferenceType: boolean @@ -197,7 +197,7 @@ preferences: 6: "Cyan" default: 0 - name: "ledStatusBlink4" - title: "LED-4 Enable Status Blink" + title: "LED-4 Enable Blink Functionality" description: "Default: Off" required: false preferenceType: boolean @@ -220,7 +220,7 @@ preferences: 6: "Cyan" default: 0 - name: "ledStatusBlink5" - title: "LED-5 Enable Status Blink" + title: "LED-5 Enable Blink Functionality" description: "Default: Off" required: false preferenceType: boolean @@ -243,7 +243,7 @@ preferences: 6: "Cyan" default: 0 - name: "ledStatusBlink6" - title: "LED-6 Enable Status Blink" + title: "LED-6 Enable Blink Functionality" description: "Default: Off" required: false preferenceType: boolean @@ -266,7 +266,7 @@ preferences: 6: "Cyan" default: 0 - name: "ledStatusBlink7" - title: "LED-7 Enable Status Blink" + title: "LED-7 Enable Blink Functionality" description: "Default: Off" required: false preferenceType: boolean diff --git a/drivers/SmartThings/zwave-switch/src/homeseer-switches/color_helper.lua b/drivers/SmartThings/zwave-switch/src/homeseer-switches/color_helper.lua index 086622a0..253e4481 100644 --- a/drivers/SmartThings/zwave-switch/src/homeseer-switches/color_helper.lua +++ b/drivers/SmartThings/zwave-switch/src/homeseer-switches/color_helper.lua @@ -39,9 +39,6 @@ local log = (require "log") --- Variables/Constants --- ---- @type string -local CAP_CACHE_KEY = "st.capabilities." .. capabilities.colorControl.ID - --- @local (table) local color = { map = { @@ -110,12 +107,14 @@ function color.set_switch_color(device, command, r, g, b) return false end + log.debug(string.format("***** HSM200 *****: set_switch_color, In function")) local hue, saturation, mylightness = utils.rgb_to_hsl(r, g, b) - log.trace(string.format("***** HSM200 Driver *****: myhue=%s,mysat=%s", device:pretty_print(),hue, saturation)) + log.debug(string.format("***** HSM200 *****: set_switch_color, RGB to HSL, hue=%s, saturation=%s",hue,saturation)) command.args.color = { hue = hue, saturation = saturation, } + local CAP_CACHE_KEY = "st.capabilities." .. capabilities.colorControl.ID device:set_field(CAP_CACHE_KEY, command) local dim_duration = constants.DEFAULT_DIMMING_DURATION @@ -129,6 +128,7 @@ function color.set_switch_color(device, command, r, g, b) }, duration = dim_duration }) + log.debug(string.format("***** HSM200 *****: set_switch_color, set=%s",set)) device:send_to_component(set, command.component) local color_check = function() diff --git a/drivers/SmartThings/zwave-switch/src/homeseer-switches/init.lua b/drivers/SmartThings/zwave-switch/src/homeseer-switches/init.lua index 94b5ef9a..13b5a7df 100644 --- a/drivers/SmartThings/zwave-switch/src/homeseer-switches/init.lua +++ b/drivers/SmartThings/zwave-switch/src/homeseer-switches/init.lua @@ -98,20 +98,17 @@ local capability_handlers = {} --- @param command (Command) Input command value --- @return (nil) function zwave_handlers.switch_multilevel_handler(driver, device, command) - -- Declare local variables 'level' and 'value' - local level = command.args.value or command.args.target_value -- Simplify if-else statement - local value = (level > 0 or level == SwitchBinary.value.ON_ENABLE) and SwitchBinary.value.ON_ENABLE - or SwitchBinary.value.OFF_DISABLE + -- Declare local variables + local level = command.args.value or command.args.target_value + local value = (level > 0 or level == SwitchBinary.value.ON_ENABLE) and SwitchBinary.value.ON_ENABLE or SwitchBinary.value.OFF_DISABLE + local event = value == SwitchBinary.value.ON_ENABLE and capabilities.switch.switch.on() or capabilities.switch.switch.off() + local endpoint = command.src_channel if command.component == "main" then local set = Basic:Set({ value=value }) device:send(set) - if value == SwitchBinary.value.ON_ENABLE then - device:emit_event(capabilities.switch.switch.on()) - else - device:emit_event(capabilities.switch.switch.off()) - end - -- If the device supports switch level capability + device:emit_event_for_endpoint(endpoint, event) + if device:supports_capability(capabilities.switchLevel, nil) then local dimmingDuration = command.args.rate or constants.DEFAULT_DIMMING_DURATION level = math.floor(level + 0.5) -- Round off 'level' to the nearest integer @@ -119,14 +116,16 @@ function zwave_handlers.switch_multilevel_handler(driver, device, command) set = SwitchMultilevel:Set({value = level, duration = dimmingDuration }) device:send(set) -- Send the 'set' command directly to the device and check for errors - local get = function() - device:send(SwitchBinary:Get({})) -- Send a 'get' command to the device to get its current status and check for errors - end - device.thread:call_with_delay(constants.DEFAULT_GET_STATUS_DELAY, get) + device.thread:call_with_delay(constants.DEFAULT_GET_STATUS_DELAY, function() + device:send(SwitchBinary:Get({})) + end) end else command.args.value = value - helpers.led.set_status_color(device, command) -- Update the LED status and check for error + local color = helpers.led.set_status_color(device, command) -- Update the LED status and check for error + log.debug(string.format("***** HomeSeer Switches *****: color=%s", color)) + event = color == SwitchBinary.value.OFF_DISABLE and capabilities.switch.switch.off() or capabilities.switch.switch.on() + device:emit_event_for_endpoint(endpoint, event) end end @@ -199,11 +198,23 @@ end function capability_handlers.do_refresh(driver, device, command) -- Determine the component for the command local component = command and command.component or "main" - local capability = device:supports_capability(capabilities.switch, component) and capabilities.switch or - device:supports_capability(capabilities.switchLevel, component) and capabilities.switchLevel or nil + local capability = device:supports_capability(capabilities.switchLevel, component) and capabilities.switchLevel or + device:supports_capability(capabilities.switch, component) and capabilities.switch or nil -- Check if the device supports switch level capability if capability then - device:send_to_component(capability == capabilities.switch and SwitchBinary:Get({}) or SwitchMultilevel:Get({}), component) + if component == "main" then + log.debug(string.format("***** HomeSeer Switches *****: I'm in the main loop")) + device:send_to_component(capability == capabilities.switch and SwitchBinary:Get({}) or SwitchMultilevel:Get({}), component) + else + log.debug(string.format("***** HomeSeer Switches *****: I'm in the component loop")) + local color_id = helpers.led.get_status_color(device,command) + log.debug(string.format("***** HomeSeer Switches *****: color=%s", color_id)) + if color_id then + device:emit_event_for_endpoint(command.src_channel,capabilities.switch.switch.on()) + else + device:emit_event_for_endpoint(command.src_channel,capabilities.switch.switch.off()) + end + end end end @@ -371,6 +382,9 @@ local homeseer_switches = { [cc.CENTRAL_SCENE] = { [CentralScene.NOTIFICATION] = zwave_handlers.emit_central_scene_events }, + [cc.BASIC] = { + [Basic.Report] = zwave_handlers.switch_multilevel_handler + }, -- Return firmware version [cc.VERSION] = { [Version.REPORT] = zwave_handlers.version_report_handler diff --git a/drivers/SmartThings/zwave-switch/src/homeseer-switches/led_helper.lua b/drivers/SmartThings/zwave-switch/src/homeseer-switches/led_helper.lua index ccc50c4c..a205af85 100644 --- a/drivers/SmartThings/zwave-switch/src/homeseer-switches/led_helper.lua +++ b/drivers/SmartThings/zwave-switch/src/homeseer-switches/led_helper.lua @@ -61,7 +61,7 @@ local led = {} --- Sets component color to closest supported color match --- @param device (st.zwave.Device) The device object --- @param command (Command) Input command value ---- @return (nil) +--- @return (number)|(nil) color function led.set_status_color(device, command) local preferences = preferencesMap.get_device_parameters(device) ---@type number @@ -108,7 +108,7 @@ function led.set_status_color(device, command) if not parameter_number or not size then --- If the parameter number or size is missing, log an error and return log.error(string.format("%s: Missing parameter number or size for component %s", device:pretty_print(), component)) - return false + return nil end --- Create a configuration set based on the parameter number, size, and value local set = Configuration:Set({ @@ -117,6 +117,27 @@ function led.set_status_color(device, command) configuration_value = value }) device:send(set) + device:update_preferences({component = parameter_number}) + return value +end +--- +--- ####################################################### + +--- ####################################################### +--- + +--- @function led.get_status_color() -- +--- Gets current component color +--- @param device (st.zwave.Device) The device object +--- @param command (Command) Input command value +--- @return (number)|(nil) color +function led.get_status_color(device, command) + ---@type string + local component = "ledStatusColor" .. string.sub(command.component, string.find(command.component, "-") + 1) + ---@type number + local color_id = device.preferences[component] + log.debug(string.format("***** HomeSeer Switches *****: led.get_status_color- color_id=%s", color_id)) + return color_id end --- --- #######################################################