Skip to content

Commit

Permalink
fixup! state tracking added back in
Browse files Browse the repository at this point in the history
  • Loading branch information
cjswedes committed Oct 8, 2024
1 parent 783d080 commit 3ea909c
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 7 deletions.
3 changes: 3 additions & 0 deletions drivers/SmartThings/philips-hue/src/fields.lua
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ local Fields = {
RESOURCE_ID = "rid",
RETRY_MIGRATION = "retry_migration",
WRAPPED_HUE = "_wrapped_hue"
COLOR_SATURATION = "color_saturation"
COLOR_HUE = "color_hue"
SWITCH_STATE = "switch_state_cache"
}

return Fields
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,10 @@ local function _emit_light_events_inner(light_device, light_repr)

if light_repr.on and light_repr.on.on then
light_device:emit_event(capabilities.switch.switch.on())
light_device:set_field(Fields.SWTICH_STATE, "on")
elseif light_repr.on and not light_repr.on.on then
light_device:emit_event(capabilities.switch.switch.off())
light_device:set_field(Fields.SWTICH_STATE, "off")
end

if light_repr.dimming then
Expand Down Expand Up @@ -96,6 +98,7 @@ local function _emit_light_events_inner(light_device, light_repr)
)
else
light_device:emit_event(capabilities.colorControl.hue(adjusted_hue))
light_device:set_field(Fields.COLOR_HUE, adjusted_hue, {persist = true})
end

if utils.is_nan(adjusted_sat) then
Expand All @@ -107,6 +110,7 @@ local function _emit_light_events_inner(light_device, light_repr)
)
else
light_device:emit_event(capabilities.colorControl.saturation(adjusted_sat))
light_device:set_field(Fields.COLOR_SATURATION, adjusted_sat, {persist = true})
end
end
end
Expand Down
10 changes: 3 additions & 7 deletions drivers/SmartThings/philips-hue/src/handlers/commands.lua
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,7 @@ local function do_switch_level_action(driver, device, args)
return
end

--Note: this will always be 0 due to state cache changes
local is_off = device:get_latest_state(
"main", capabilities.switch.ID, capabilities.switch.switch.NAME) == "off"
local is_off = device:get_field(Fields.SWITCH_STATE) == "off"

if is_off then
local resp, err = hue_api:set_light_on_state(light_id, true)
Expand Down Expand Up @@ -178,9 +176,8 @@ end
---@param args table
local function do_setHue_action(driver, device, args)

--Note: this will always be 0 due to state cache changes
-- Use existing 'saturation' value for device or set to 0 and pass arg values to function 'do_color_action'
local currentSaturation = device:get_latest_state("main", capabilities.colorControl.ID, capabilities.colorControl.saturation.NAME, 0)
local currentSaturation = device:get_field(Fields.COLOR_SATURATION) or 0
args.args.color = {
hue = args.args.hue,
saturation = currentSaturation
Expand All @@ -194,9 +191,8 @@ end
---@param args table
local function do_setSaturation_action(driver, device, args)

--Note: this will always be 0 due to state cache changes
-- Use existing 'hue' value for device or set to 0 and pass arg values to function 'do_color_action'
local currentHue = device:get_latest_state("main", capabilities.colorControl.ID, capabilities.colorControl.hue.NAME, 0)
local currentHue = device:get_field(Fields.COLOR_HUE) or 0
args.args.color = {
hue = currentHue,
saturation = args.args.saturation
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
local log = require "log"
local st_utils = require "st.utils"
local capabilities = require "st.capabilities"

local Discovery = require "disco"
local Fields = require "fields"
Expand Down

0 comments on commit 3ea909c

Please sign in to comment.