Skip to content

Commit

Permalink
fixup! fix: Update refresh to poll connectivity status
Browse files Browse the repository at this point in the history
  • Loading branch information
dljsjr committed Oct 18, 2023
1 parent fcf3ae8 commit 23ae1a9
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
9 changes: 8 additions & 1 deletion drivers/SmartThings/philips-hue/src/handlers.lua
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,7 @@ local function do_refresh_light(driver, light_device, conn_status_cache, light_s

local do_zigbee_request = true
local do_light_request = true
local light_online = true

if type(conn_status_cache) == "table" then
local zigbee_status = conn_status_cache[hue_device_id]
Expand All @@ -264,8 +265,10 @@ local function do_refresh_light(driver, light_device, conn_status_cache, light_s
light_device:online()
do_zigbee_request = false
else
light_device.log.debug(string.format("Zigbee Status for %s is not connected", light_device.label))
light_device:offline()
do_zigbee_request = false
light_online = false
end
end
end
Expand Down Expand Up @@ -357,7 +360,9 @@ local function do_refresh_light(driver, light_device, conn_status_cache, light_s
light_device.log.debug(string.format("Zigbee Status for %s is connected", light_device.label))
light_device:online()
else
light_device.log.debug(string.format("Zigbee Status for %s is not connected", light_device.label))
light_device:offline()
light_online = false
end
end
end
Expand Down Expand Up @@ -385,7 +390,9 @@ local function do_refresh_light(driver, light_device, conn_status_cache, light_s
if light_info.color ~= nil and light_info.color.gamut then
light_device:set_field(Fields.GAMUT, light_info.color.gamut_type, { persist = true })
end
driver.emit_light_status_events(light_device, light_info)
if light_online then
driver.emit_light_status_events(light_device, light_info)
end
success = true
end
end
Expand Down
2 changes: 1 addition & 1 deletion drivers/SmartThings/philips-hue/src/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -680,10 +680,10 @@ light_added = function(driver, device, parent_device_id, resource_id)
device:set_field(Fields.PARENT_DEVICE_ID, light_info.parent_device_id, { persist = true })
device:set_field(Fields.RESOURCE_ID, device_light_resource_id, { persist = true })
device:set_field(Fields._ADDED, true, { persist = true })
device:set_field(Fields._REFRESH_AFTER_INIT, true, { persist = true })

driver.light_id_to_device[device_light_resource_id] = device

device:online()
-- the refresh handler adds lights that don't have a fully initialized bridge to a queue.
handlers.refresh_handler(driver, device)
end
Expand Down

0 comments on commit 23ae1a9

Please sign in to comment.