Skip to content

Commit

Permalink
fix: Don't emit events for bulbs known offline
Browse files Browse the repository at this point in the history
Requires tracking some non-persistent state for devices.
  • Loading branch information
dljsjr committed Aug 23, 2023
1 parent 78af946 commit 731e777
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
1 change: 1 addition & 0 deletions drivers/SmartThings/philips-hue/src/hue/fields.lua
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ local Fields = {
MIN_DIMMING = "mindim",
MIN_KELVIN = "mintemp",
MODEL_ID = "modelid",
IS_ONLINE = "is_online",
PARENT_DEVICE_ID = "parent_device_id_local",
RESOURCE_ID = "rid",
WRAPPED_HUE = "_wrapped_hue"
Expand Down
9 changes: 9 additions & 0 deletions drivers/SmartThings/philips-hue/src/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,18 @@ local function emit_light_status_events(light_device, light)
if light.status then
if light.status == "connected" then
light_device:online()
light_device:set_field(Fields.IS_ONLINE, true)
elseif light.status == "connectivity_issue" then
light_device:offline()
light_device:set_field(Fields.IS_ONLINE, false)
return
end
end

if not light_device:get_field(Fields.IS_ONLINE) then
return
end

if light.mode then
light_device:emit_event(hueSyncMode.mode(light.mode))
end
Expand Down Expand Up @@ -681,6 +687,7 @@ light_added = function(driver, device, parent_device_id, resource_id)

driver.light_id_to_device[device_light_resource_id] = device

light_device:set_field(Fields.IS_ONLINE, true)
device:online()
-- the refresh handler adds lights that don't have a fully initialized bridge to a queue.
handlers.refresh_handler(driver, device)
Expand Down Expand Up @@ -751,8 +758,10 @@ local function do_bridge_network_init(driver, device, bridge_url, api_key)
if status.status == "connected" then
child_device.log.trace("Marking Online after SSE Reconnect")
child_device:online()
child_device:set_field(Fields.IS_ONLINE, true)
elseif status.status == "connectivity_issue" then
child_device.log.trace("Marking Offline after SSE Reconnect")
child_device:set_field(Fields.IS_ONLINE, false)
child_device:offline()
end
end
Expand Down

0 comments on commit 731e777

Please sign in to comment.