Skip to content

Commit 3fc413e

Browse files
committed
fix: Multi-button service mapping improvements.
For multi-button devices, we were waiting to populate the mappings to associate the multiple button service resources to the single device record from the API responses we perform during the `init` handler. This could lead to inconsistent state or failure to maintain mappings in situations where those API calls failed for any reason. We still need to make those API calls during `init` to establish the current state of the device, but we now populate the mappings from cached data (if it exists) instead of relying on those initial API calls to resolve properly.
1 parent a512c65 commit 3fc413e

File tree

1 file changed

+19
-0
lines changed
  • drivers/SmartThings/philips-hue/src/handlers/lifecycle_handlers

1 file changed

+19
-0
lines changed

drivers/SmartThings/philips-hue/src/handlers/lifecycle_handlers/button.lua

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,25 @@ function ButtonLifecycleHandlers.init(driver, device)
119119
if not hue_id_to_device[device_button_resource_id] then
120120
hue_id_to_device[device_button_resource_id] = device
121121
end
122+
123+
local maybe_idx_map = device:get_field(Fields.BUTTON_INDEX_MAP)
124+
local svc_rids_for_device = driver.services_for_device_rid[hue_device_id] or {}
125+
126+
if not svc_rids_for_device[device_button_resource_id] then
127+
svc_rids_for_device[device_button_resource_id] = HueDeviceTypes.BUTTON
128+
end
129+
130+
for resource_id, _ in pairs(maybe_idx_map or {}) do
131+
if not hue_id_to_device[resource_id] then
132+
hue_id_to_device[resource_id] = device
133+
end
134+
135+
if not svc_rids_for_device[resource_id] then
136+
svc_rids_for_device[resource_id] = HueDeviceTypes.BUTTON
137+
end
138+
end
139+
driver.services_for_device_rid[hue_device_id] = svc_rids_for_device
140+
122141
local button_info, err
123142
button_info = Discovery.device_state_disco_cache[device_button_resource_id]
124143
if not button_info then

0 commit comments

Comments
 (0)