Skip to content

Commit

Permalink
Fixed a couple of hold over items for the FC200, and updated the HSM2…
Browse files Browse the repository at this point in the history
…00 code (#75)
  • Loading branch information
jshessen authored Feb 17, 2023
2 parents ebb19c1 + 6b6829a commit fbcd91c
Show file tree
Hide file tree
Showing 3 changed files with 122 additions and 46 deletions.
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
# Change Log

## [0.7.2-beta.2](https://github.com/jshessen/SmartThingsEdgeDrivers/compare/v0.7.2-beta.1...v0.7.2-beta.2) (2023-02-17)


### :hammer_and_wrench: Bug Fixes

* **fan:** include local helpers ([c3ee22f](https://github.com/jshessen/SmartThingsEdgeDrivers/commit/c3ee22fce87f6d646edaeddc8172eeae7bdf8253))

## [0.7.2-beta.1](https://github.com/jshessen/SmartThingsEdgeDrivers/compare/v0.7.1...v0.7.2-beta.1) (2023-02-17)


### :hammer_and_wrench: Bug Fixes

* **fan:** can_handle function name ([938a712](https://github.com/jshessen/SmartThingsEdgeDrivers/commit/938a712a9ae21b0d69ff663686d8f0b8e178ec9a))

## [0.7.1](https://github.com/jshessen/SmartThingsEdgeDrivers/compare/v0.7.0...v0.7.1) (2023-02-17)


Expand Down
10 changes: 7 additions & 3 deletions drivers/SmartThings/zwave-fan/src/homeseer-fan/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ local CentralScene = (require "st.zwave.CommandClass.CentralScene")({version = 1
--- Misc
--- @type Version
local Version = (require "st.zwave.CommandClass.Version")({version = 3})

local fan_speed_helper = (require "zwave_fan_helpers")
local zwave_fan_3_speed = (require "zwave-fan-3-speed")
local zwave_fan_4_speed = (require "zwave-fan-4-speed")
--- @type table
local helpers = {}
helpers.color = (require "homeseer-switches.color_helper")
Expand All @@ -62,14 +66,14 @@ local HOMESEER_FAN_FINGERPRINTS = {
{id = "HomeSeer/Dimmer/WD200", mfr = 0x000C, prod = 0x0203, model = 0x0001}, -- HomeSeer FC200 Fan Controller
}

--- @function can_handle_homeseer_switches() --
--- @function can_handle_homeseer_fan_controller() --
--- Determine whether the passed device is a HomeSeer Fan Controller.
--- @param opts (table)
--- @param driver (Driver) The driver object
--- @param device (st.zwave.Device) The device object
--- @vararg ... any
--- @return (boolean)
local function can_handle_homeseer_switches(opts, driver, device, ...)
local function can_handle_homeseer_fan_controller(opts, driver, device, ...)
for _, fingerprint in ipairs(HOMESEER_FAN_FINGERPRINTS) do
if device:id_match(fingerprint.mfr, fingerprint.prod, fingerprint.model) then
return true
Expand Down Expand Up @@ -135,7 +139,7 @@ capability_handlers.switch_color_handler = zwave_handlers.switch_color_handler
--- @param device (st.zwave.Device) The device object
--- @param command (Command) Input command value
function zwave_handlers.version_report_handler(driver, device, command)
command.args.fingerprints = HOMESEER_SWITCH_FINGERPRINTS
command.args.fingerprints = HOMESEER_FAN_FINGERPRINTS
local profile = helpers.profile.get_device_profile(device,command.args)
if profile then
assert (device:try_update_metadata({profile = profile}), "Failed to change device profile")
Expand Down
144 changes: 101 additions & 43 deletions drivers/SmartThings/zwave-sensor/src/homeseer-hsm200-sensor/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -12,55 +12,98 @@
-- See the License for the specific language governing permissions and
-- limitations under the License.

-- @type st.capabilities
local capabilities = require "st.capabilities"
-- @type st.utils
local utils = require "st.utils"
--- @type st.zwave.CommandClass
--- @type st.zwave.Device
local st_device = require "st.zwave.device"
-- @type st.zwave.CommandClass
local cc = require "st.zwave.CommandClass"
--- @type st.zwave.constants

-- @type st.zwave.constants
local constants = require "st.zwave.constants"
--- @type st.zwave.CommandClass.Basic
local Basic = (require "st.zwave.CommandClass.Basic")({version=1,strict=true})
--- @type st.zwave.CommandClass.SwitchColor
local SwitchColor = (require "st.zwave.CommandClass.SwitchColor")({version=3,strict=true})
--- @type st.zwave.CommandClass.SwitchBinary
local SwitchBinary = (require "st.zwave.CommandClass.SwitchBinary")({version=2,strict=true})
--- @type st.zwave.CommandClass.Notification
local Notification = (require "st.zwave.CommandClass.Notification")({version=4})
-- @type st.utils
local utils = require "st.utils"
-- @type log
local log = require "log"
local preferences = require "preferences"


--- Switch
--- @type Basic
local Basic = (require "st.zwave.CommandClass.Basic")({version = 2, strict = true})
--- @type SwitchBinary
local SwitchBinary = (require "st.zwave.CommandClass.SwitchBinary")({version = 2, strict = true})

--- Notification
--- @type SwitchMultilevel
local Notification = (require "st.zwave.CommandClass.Notification")({version = 3})

--- Misc
--- @type Version
local Version = (require "st.zwave.CommandClass.Version")({version = 3})
--- @type table
local helpers = {}
helpers.color = (require "homeseer-switches.color_helper")


local CAP_CACHE_KEY = "st.capabilities." .. capabilities.colorControl.ID

local HOMESEER_MULTIPURPOSE_SENSOR_FINGERPRINTS = {
{ manufacturerId = 0x001E, productType = 0x0004, productId = 0x0001 }, -- EZmultiPli
{ manufacturerId = 0x0004, productType = 0x0004, productId = 0x0001 } -- HomeSeer HSM200
{ id = "HomeSeer/Sensor/HSM200", manufacturerId = 0x001E, productType = 0x0004, productId = 0x0001 }, -- EZmultiPli
{ id = "EZmultiPli/Sensor/EZMP", manufacturerId = 0x0004, productType = 0x0004, productId = 0x0001 } -- HomeSeer HSM200
}

--- @function can_handle_homeseer_multipurpose_sensor() --
--- Determine whether the passed device is a HomeSeer sensor.
--- @param opts (table)
--- @param driver (Driver) The driver object
--- @param device (st.zwave.Device) The device object
--- @vararg ... any
--- @return (boolean)
local function can_handle_homeseer_multipurpose_sensor(opts, driver, device, ...)
for _, fingerprint in ipairs(HOMESEER_MULTIPURPOSE_SENSOR_FINGERPRINTS) do
if device:id_match(fingerprint.manufacturerId, fingerprint.productType, fingerprint.productId) then
if device:id_match(fingerprint.mfr, fingerprint.prod, fingerprint.model) then
return true
end
end
return false
end

local function basic_report_handler(driver, device, cmd)
local event
local value = (cmd.args.target_value ~= nil) and cmd.args.target_value or cmd.args.value


--- @local table
local zwave_handlers = {}
--- @local table
local capability_handlers = {}

--- @function zwave_handlers.basic_report_handler() --
--- Handles basic report commands for a Z-Wave switch device.
--- @param driver (Driver) The driver instance.
--- @param device (st.zwave.Device) The device instance.
--- @param command (Command) The command table.
function zwave_handlers.basic_report_handler(driver, device, command)
local value = command.args.target_value or command.args.value
if value == SwitchBinary.value.OFF_DISABLE then
event = capabilities.switch.switch.off()
device:emit_event_for_endpoint(cmd.src_channel, capabilities.colorControl.hue(0))
device:emit_event_for_endpoint(cmd.src_channel, capabilities.colorControl.saturation(0))
local hueEvent = capabilities.colorControl.hue(0)
local saturationEvent = capabilities.colorControl.saturation(0)
local offEvent = capabilities.switch.switch.off()

if not device:emit_event_for_endpoint(command.src_channel, offEvent) then
log.error(string.format("%s: Failed to emit event for turning off the switch.", device:pretty_print()))
end
if not device:emit_event_for_endpoint(command.src_channel, hueEvent, saturationEvent) then
log.error(string.format("%s: Failed to emit event for setting hue and saturation to 0.", device:pretty_print()))
end
else
event = capabilities.switch.switch.on()
local onEvent = capabilities.switch.switch.on()
if not device:emit_event_for_endpoint(command.src_channel, onEvent) then
log.error(string.format("%s: Failed to emit event for turning on the switch.", device:pretty_print()))
end
end

device:emit_event_for_endpoint(cmd.src_channel, event)
end



local TIMER = "timed_clear"
local function notification_report_handler(self, device, cmd)
local event
Expand All @@ -87,43 +130,58 @@ local function notification_report_handler(self, device, cmd)
end
end

local function set_color(driver, device, command)
local hue = command.args.color.hue
local saturation = command.args.color.saturation

local duration = constants.DEFAULT_DIMMING_DURATION
local r, g, b = utils.hsl_to_rgb(hue, saturation, nil)

r = (r >= 191) and 255 or 0
g = (g >= 191) and 255 or 0
b = (b >= 191) and 255 or 0

local myhue, mysaturation = utils.rgb_to_hsl(r, g, b)
--- @function zwave_handlers.switch_color_handler() --
--- Sets the switch color for a device based on a command.
--- @param driver (Driver) The driver object.
--- @param device (st.zwave.Device) The device object.
--- @param command (table) The input command.
function zwave_handlers.switch_color_handler(driver, device, command)
local value = command.args.value
local color
if command.args.color then
color = helpers.color.find_closest_color(command.args.color.hue, command.args.color.saturation, command.args.color.lightness)
else
color = helpers.color.map[7]
end

command.args.color.hue = myhue
command.args.color.saturation = mysaturation
local r, g, b = helpers.color.hex_to_rgb(color.hex)
if not r then
log.error(string.format("%s: Failed to convert color hex to RGB. color.hex=%s", device:pretty_print(), color.hex))
return
end

local hue, saturation, lightness = utils.rgb_to_hsl(r, g, b)
command.args.color = {
hue = hue,
saturation = saturation,
}
device:set_field(CAP_CACHE_KEY, command)

helpers.color.set_switch_color(device, command, r,g,b)
local success, err_msg = pcall(helpers.color.set_switch_color, device, command, r, g, b)
if not success then
log.error(string.format("%s: Failed to set color for device. Error: %s", device:pretty_print(), err_msg))
end
end
capability_handlers.switch_color_handler = zwave_handlers.switch_color_handler



local homeseer_multipurpose_sensor = {
NAME = "HomeSeer Multipurpose Sensor",
zwave_handlers = {
[cc.BASIC] = {
[Basic.REPORT] = basic_report_handler
[Basic.REPORT] = zwave_handlers.basic_report_handler
},
--[[ [cc.NOTIFICATIONS] = {
[Notification.REPORT] = notification_report_handler
[Notification.REPORT] = zwave_handlers.notification_report_handler
} ]]
},
capability_handlers = {
[capabilities.colorControl.ID] = {
[capabilities.colorControl.commands.setColor.NAME] = set_color
[capabilities.colorControl.commands.setColor.NAME] = capability_handlers.switch_color_handler
}
},
can_handle = can_handle_homeseer_multipurpose_sensor
}

return homeseer_multipurpose_sensor
return homeseer_multipurpose_sensor

0 comments on commit fbcd91c

Please sign in to comment.