From 23ae1a93195c205cd0e2d3c2700ec5715bffab94 Mon Sep 17 00:00:00 2001 From: Doug Stephen Date: Wed, 18 Oct 2023 11:30:53 -0500 Subject: [PATCH] fixup! fix: Update refresh to poll connectivity status --- drivers/SmartThings/philips-hue/src/handlers.lua | 9 ++++++++- drivers/SmartThings/philips-hue/src/init.lua | 2 +- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/drivers/SmartThings/philips-hue/src/handlers.lua b/drivers/SmartThings/philips-hue/src/handlers.lua index 6d790b428c..ab1fe7ad51 100644 --- a/drivers/SmartThings/philips-hue/src/handlers.lua +++ b/drivers/SmartThings/philips-hue/src/handlers.lua @@ -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] @@ -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 @@ -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 @@ -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 diff --git a/drivers/SmartThings/philips-hue/src/init.lua b/drivers/SmartThings/philips-hue/src/init.lua index aafe738bc2..5d7ed71f5f 100644 --- a/drivers/SmartThings/philips-hue/src/init.lua +++ b/drivers/SmartThings/philips-hue/src/init.lua @@ -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