Skip to content

Commit 6ffe56b

Browse files
authored
Merge branch 'main' into shina_button
2 parents 31090e1 + e87aaec commit 6ffe56b

File tree

17 files changed

+1047
-241
lines changed

17 files changed

+1047
-241
lines changed

drivers/SmartThings/philips-hue/src/handlers/attribute_emitters.lua

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,11 @@ function AttributeEmitters.connectivity_update(child_device, zigbee_status)
175175
child_device.log.info_with({hub_logs=true}, "Device zigbee status event, marking device online")
176176
child_device:online()
177177
child_device:set_field(Fields.IS_ONLINE, true)
178+
child_device.driver:inject_capability_command(child_device, {
179+
capability = capabilities.refresh.ID,
180+
command = capabilities.refresh.commands.refresh.NAME,
181+
args = {}
182+
})
178183
elseif zigbee_status.status == "connectivity_issue" then
179184
child_device.log.info_with({hub_logs=true}, "Device zigbee status event, marking device offline")
180185
child_device:set_field(Fields.IS_ONLINE, false)

drivers/SmartThings/sonos/src/api/cmd_handlers.lua

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ local CapCommandHandlers = {}
1111

1212
local QUEUE_ACTION_PREF = "queueAction"
1313

14-
local function _do_send(device, payload)
14+
local function _do_send(device, payload, use_coordinator)
1515
local conn = device:get_field(PlayerFields.CONNECTION)
1616
if conn and conn:is_running() then
17-
conn:send_command(payload)
17+
conn:send_command(payload, use_coordinator)
1818
else
1919
log.warn("No sonos connection for handling capability command")
2020
end
@@ -33,7 +33,7 @@ local function _do_send_to_group(driver, device, payload)
3333
payload[1].authorization = string.format("Bearer %s", maybe_token.accessToken)
3434
end
3535

36-
_do_send(device, payload)
36+
_do_send(device, payload, true)
3737
end
3838

3939
local function _do_send_to_self(driver, device, payload)
@@ -48,7 +48,7 @@ local function _do_send_to_self(driver, device, payload)
4848
if maybe_token then
4949
payload[1].authorization = string.format("Bearer %s", maybe_token.accessToken)
5050
end
51-
_do_send(device, payload)
51+
_do_send(device, payload, false)
5252
end
5353

5454
function CapCommandHandlers.handle_play(driver, device, _cmd)

drivers/SmartThings/sonos/src/api/event_handlers.lua

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ CapEventHandlers.PlaybackStatus = {
99
Buffering = "PLAYBACK_STATE_BUFFERING",
1010
Idle = "PLAYBACK_STATE_IDLE",
1111
Paused = "PLAYBACK_STATE_PAUSED",
12-
Playing = "PLAYBACK_STATE_PLAYING"
12+
Playing = "PLAYBACK_STATE_PLAYING",
1313
}
1414

1515
function CapEventHandlers.handle_player_volume(device, new_volume, is_muted)
@@ -84,7 +84,12 @@ function CapEventHandlers.handle_playback_metadata_update(device, metadata_statu
8484
local is_linein = string.find(metadata_status_body.container.type, "linein", 1, true) ~= nil
8585
local is_station = string.find(metadata_status_body.container.type, "station", 1, true) ~= nil
8686
local is_show = string.find(metadata_status_body.container.type, "show", 1, true) ~= nil
87-
local is_radio_tracklist = string.find(metadata_status_body.container.type, "trackList.program", 1, true) ~= nil
87+
local is_radio_tracklist = string.find(
88+
metadata_status_body.container.type,
89+
"trackList.program",
90+
1,
91+
true
92+
) ~= nil
8893

8994
if is_linein then
9095
audio_track_data.title = metadata_status_body.container.name
@@ -101,8 +106,7 @@ function CapEventHandlers.handle_playback_metadata_update(device, metadata_statu
101106
if metadata_status_body.track then
102107
track_info = metadata_status_body.track
103108
elseif metadata_status_body.currentItem and metadata_status_body.currentItem.track then
104-
track_info = metadata_status_body
105-
.currentItem.track
109+
track_info = metadata_status_body.currentItem.track
106110
end
107111

108112
if track_info ~= nil then

drivers/SmartThings/sonos/src/api/sonos_connection.lua

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,11 @@ local _update_subscriptions_helper = function(
7878
local unique_key, bad_key_part = utils.sonos_unique_key(householdId, playerId)
7979
if not unique_key then
8080
local err_msg = string.format("Invalid Sonos Unique Key Part: %s", bad_key_part)
81-
reply_tx:send(table.pack(nil, err_msg))
81+
if reply_tx then
82+
reply_tx:send(table.pack(nil, err_msg))
83+
else
84+
log.warn(string.format("Update Subscriptions Error: %s", err_msg))
85+
end
8286
return
8387
end
8488
Router.send_message_to_player(unique_key, payload, reply_tx)
@@ -462,8 +466,11 @@ function SonosConnection.new(driver, device)
462466
local base_url = lb_utils.force_url_table(
463467
string.format("https://%s:%s", url_ip, SonosApi.DEFAULT_SONOS_PORT)
464468
)
469+
local _, api_key = driver:check_auth(device)
470+
local maybe_token = driver:get_oauth_token()
471+
local headers = SonosApi.make_headers(api_key, maybe_token and maybe_token.accessToken)
465472
local favorites_response, err, _ =
466-
SonosRestApi.get_favorites(base_url, header.householdId)
473+
SonosRestApi.get_favorites(base_url, header.householdId, headers)
467474

468475
if err or not favorites_response then
469476
log.error("Error querying for favorites: " .. err)
@@ -582,15 +589,21 @@ end
582589

583590
--- Send a Sonos command object to the player for this connection
584591
--- @param cmd SonosCommand
585-
function SonosConnection:send_command(cmd)
592+
--- @param use_coordinator boolean
593+
function SonosConnection:send_command(cmd, use_coordinator)
586594
log.debug("Sending command over websocket channel for device " .. self.device.label)
587-
local household_id, coordinator_id = self.driver.sonos:get_coordinator_for_device(self.device)
595+
local household_id, target_id
596+
if use_coordinator then
597+
household_id, target_id = self.driver.sonos:get_coordinator_for_device(self.device)
598+
else
599+
household_id, target_id = self.driver.sonos:get_player_for_device(self.device)
600+
end
588601
local json_payload, err = json.encode(cmd)
589602

590603
if err or not json_payload then
591604
log.error("Json encoding error: " .. err)
592605
else
593-
local unique_key, bad_key_part = utils.sonos_unique_key(household_id, coordinator_id)
606+
local unique_key, bad_key_part = utils.sonos_unique_key(household_id, target_id)
594607
if not unique_key then
595608
self.device.log.error(string.format("Invalid Sonos Unique Key Part: %s", bad_key_part))
596609
return

drivers/SmartThings/sonos/src/api/sonos_ssdp_discovery.lua

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,6 @@ local function make_persistent_task_impl(
9999
interval_timer:handled()
100100
ssdp_search_handle:multicast_m_search()
101101
elseif receiver == control_rx then
102-
---@type ControlMessage?,string?
103102
local recv, recv_err = receiver:receive()
104103
if not recv then
105104
log.warn(string.format("control channel receive error: %s", recv_err))

drivers/SmartThings/sonos/src/sonos_state.lua

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -183,8 +183,9 @@ end
183183
function SonosState:update_device_record_group_info(household, group, device)
184184
local player_id = device:get_field(PlayerFields.PLAYER_ID)
185185
local group_role
186-
if player_id == group.coordinatorId then
187-
if #household.groups[group.id].playerIds > 1 then
186+
if (player_id and group and group.id and group.coordinatorId) and player_id == group.coordinatorId then
187+
local player_ids_list = household.groups[group.id].playerIds or {}
188+
if #player_ids_list > 1 then
188189
group_role = "primary"
189190
else
190191
group_role = "ungrouped"
@@ -248,7 +249,7 @@ end
248249
--- @param household_id HouseholdId
249250
--- @param device SonosDevice
250251
function SonosState:update_device_record_from_state(household_id, device)
251-
local current_mapping = _STATE.device_record_map[device.id]
252+
local current_mapping = _STATE.device_record_map[device.id] or {}
252253
local household = _STATE.households:get_or_init(household_id)
253254
self:update_device_record_group_info(household, current_mapping.group, device)
254255
end

drivers/SmartThings/zigbee-motion-sensor/fingerprints.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -159,15 +159,15 @@ zigbeeManufacturer:
159159
model: VMS_ADUROLIGHT
160160
deviceProfileName: motion-battery
161161
- id: frientA/S/140
162-
deviceLabel: frient Motion Sensor
162+
deviceLabel: frient Motion Sensor Pro
163163
manufacturer: frient A/S
164164
model: MOSZB-140
165-
deviceProfileName: motion-temp-battery
165+
deviceProfileName: frient-motion-temp-illuminance-tamper-battery
166166
- id: frientA/S/141
167167
deviceLabel: frient Motion Sensor
168168
manufacturer: frient A/S
169169
model: MOSZB-141
170-
deviceProfileName: motion-battery
170+
deviceProfileName: frient-motion-battery
171171
- id: Compacta/ZBMS3-1
172172
deviceLabel: Smartenit Motion Sensor
173173
manufacturer: Compacta
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
name: frient-motion-battery
2+
components:
3+
- id: main
4+
capabilities:
5+
- id: motionSensor
6+
version: 1
7+
- id: battery
8+
version: 1
9+
- id: firmwareUpdate
10+
version: 1
11+
- id: refresh
12+
version: 1
13+
categories:
14+
- name: MotionSensor
15+
preferences:
16+
- title: "Motion Turn-Off Delay (s)"
17+
name: occupiedToUnoccupiedD
18+
description: "Delay in seconds to report after no motion is detected"
19+
required: false
20+
preferenceType: integer
21+
definition:
22+
minimum: 0
23+
maximum: 65534
24+
default: 240
25+
- title: "Motion Turn-On Delay (s)"
26+
name: unoccupiedToOccupiedD
27+
description: "Delay in seconds to report after motion is detected"
28+
required: false
29+
preferenceType: integer
30+
definition:
31+
minimum: 0
32+
maximum: 65534
33+
default: 0
34+
- title: "Movement Threshold in Turn-On Delay"
35+
name: unoccupiedToOccupiedT
36+
description: "Number of movements to detect before reporting motion during the Motion Turn-On Delay"
37+
required: false
38+
preferenceType: integer
39+
definition:
40+
minimum: 1
41+
maximum: 254
42+
default: 1
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
name: frient-motion-temp-illuminance-tamper-battery
2+
components:
3+
- id: main
4+
capabilities:
5+
- id: motionSensor
6+
version: 1
7+
- id: temperatureMeasurement
8+
version: 1
9+
- id: illuminanceMeasurement
10+
version: 1
11+
- id: battery
12+
version: 1
13+
- id: tamperAlert
14+
version: 1
15+
- id: firmwareUpdate
16+
version: 1
17+
- id: refresh
18+
version: 1
19+
categories:
20+
- name: MotionSensor
21+
preferences:
22+
- preferenceId: tempOffset
23+
explicit: true
24+
- title: "Temperature Sensitivity (°C)"
25+
name: temperatureSensitivity
26+
description: "Minimum change in temperature to report"
27+
required: false
28+
preferenceType: number
29+
definition:
30+
minimum: 0.1
31+
maximum: 2.0
32+
default: 1.0
33+
- title: "Motion Turn-Off Delay (s)"
34+
name: occupiedToUnoccupiedD
35+
description: "Delay in seconds to report after no motion is detected"
36+
required: false
37+
preferenceType: integer
38+
definition:
39+
minimum: 0
40+
maximum: 65534
41+
default: 240
42+
- title: "Motion Turn-On Delay (s)"
43+
name: unoccupiedToOccupiedD
44+
description: "Delay in seconds to report after motion is detected"
45+
required: false
46+
preferenceType: integer
47+
definition:
48+
minimum: 0
49+
maximum: 65534
50+
default: 0
51+
- title: "Movement Threshold in Turn-On Delay"
52+
name: unoccupiedToOccupiedT
53+
description: "Number of movements to detect before reporting motion during the Motion Turn-On Delay"
54+
required: false
55+
preferenceType: integer
56+
definition:
57+
minimum: 1
58+
maximum: 254
59+
default: 1

0 commit comments

Comments
 (0)