From 007b23184e9b6f092bdd14155dfdc7e84ee8cebb Mon Sep 17 00:00:00 2001 From: Kiera Robinson Date: Sat, 27 Apr 2024 14:00:56 -0500 Subject: [PATCH] Added support for the Philips Hue Smart Plug; Philips Hue Smart Plug is exposed as a 'light' service so existing light code was modified to include the case for Philips Hue Smart Plug new device adoption and use --- drivers/SmartThings/philips-hue/profiles/plug.yml | 12 ++++++++++++ drivers/SmartThings/philips-hue/src/disco/light.lua | 4 +++- drivers/SmartThings/philips-hue/src/hue/api.lua | 6 +++--- drivers/SmartThings/philips-hue/src/utils.lua | 1 + 4 files changed, 19 insertions(+), 4 deletions(-) create mode 100644 drivers/SmartThings/philips-hue/profiles/plug.yml diff --git a/drivers/SmartThings/philips-hue/profiles/plug.yml b/drivers/SmartThings/philips-hue/profiles/plug.yml new file mode 100644 index 0000000000..e5901cff1b --- /dev/null +++ b/drivers/SmartThings/philips-hue/profiles/plug.yml @@ -0,0 +1,12 @@ +name: plug +components: +- id: main + capabilities: + - id: switch + version: 1 + - id: samsungim.hueSyncMode + version: 1 + - id: refresh + version: 1 + categories: + - name: SmartPlug diff --git a/drivers/SmartThings/philips-hue/src/disco/light.lua b/drivers/SmartThings/philips-hue/src/disco/light.lua index 5bade096c4..243a2417d9 100644 --- a/drivers/SmartThings/philips-hue/src/disco/light.lua +++ b/drivers/SmartThings/philips-hue/src/disco/light.lua @@ -64,10 +64,12 @@ function M.handle_discovered_device( profile_ref = "white-ambiance" -- all color temp products support `white` (dimming) elseif light.dimming then profile_ref = "white" -- `white` refers to dimmable and includes filament bulbs + elseif light.on then -- Case for plug which uses same category as 'light' + profile_ref = "plug" else log.warn( string.format( - "Light resource [%s] does not seem to be A White/White-Ambiance/White-Color-Ambiance device, currently unsupported" + "Light resource [%s] does not seem to be A White/White-Ambiance/White-Color-Ambiance/Plug device, currently unsupported" , resource_id ) diff --git a/drivers/SmartThings/philips-hue/src/hue/api.lua b/drivers/SmartThings/philips-hue/src/hue/api.lua index de63c874f7..191c7474cb 100644 --- a/drivers/SmartThings/philips-hue/src/hue/api.lua +++ b/drivers/SmartThings/philips-hue/src/hue/api.lua @@ -323,21 +323,21 @@ function PhilipsHueApi:get_rooms() return self:get_all_reprs_for_rtype("room") e ---@return HueResourceResponse? ---@return string? err nil on success function PhilipsHueApi:get_light_by_id(light_resource_id) - return self:get_rtype_by_rid(HueDeviceTypes.LIGHT, light_resource_id) + return self:get_rtype_by_rid(HueDeviceTypes.LIGHT, light_resource_id) --[[@as HueResourceResponse]] end ---@param hue_device_id string ---@return HueResourceResponse? ---@return string? err nil on success function PhilipsHueApi:get_device_by_id(hue_device_id) - return self:get_rtype_by_rid("device", hue_device_id) + return self:get_rtype_by_rid("device", hue_device_id) --[[@as HueResourceResponse]] end ---@param zigbee_resource_id string ---@return HueResourceResponse? ---@return string? err nil on success function PhilipsHueApi:get_zigbee_connectivity_by_id(zigbee_resource_id) - return self:get_rtype_by_rid("zigbee_connectivity", zigbee_resource_id) + return self:get_rtype_by_rid("zigbee_connectivity", zigbee_resource_id) --[[@as HueResourceResponse]] end ---@param contact_resource_id string diff --git a/drivers/SmartThings/philips-hue/src/utils.lua b/drivers/SmartThings/philips-hue/src/utils.lua index 78cf7c42da..fa82c77afd 100644 --- a/drivers/SmartThings/philips-hue/src/utils.lua +++ b/drivers/SmartThings/philips-hue/src/utils.lua @@ -53,6 +53,7 @@ end function utils.kelvin_to_mirek(kelvin) return 1000000 / kelvin end function utils.mirek_to_kelvin(mirek) return 1000000 / mirek end + function utils.str_starts_with(str, start) return str:sub(1, #start) == start end