Skip to content

Commit

Permalink
Merge pull request #993 from SmartThingsCommunity/main
Browse files Browse the repository at this point in the history
Rolling up main to beta
  • Loading branch information
greens authored Sep 26, 2023
2 parents 4ba02f9 + ca34ebe commit 01cfa70
Show file tree
Hide file tree
Showing 25 changed files with 1,808 additions and 73 deletions.
6 changes: 3 additions & 3 deletions drivers/SmartThings/matter-sensor/fingerprints.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ matterManufacturer:
deviceLabel: Eve Motion
vendorId: 0x130a
productId: 0x0059
deviceProfileName: matter-motion-battery-illuminance
deviceProfileName: motion-illuminance-battery
- id: "Eve/DoorAndWindow"
deviceLabel: Eve Door and Window
vendorId: 0x130a
Expand Down Expand Up @@ -49,12 +49,12 @@ matterGeneric:
deviceTypes:
- id: 0x0107 # Occupancy Sensor
- id: 0x0106 # Light Sensor
deviceProfileName: matter-motion-battery-illuminance
deviceProfileName: motion-illuminance-battery
- id: "matter/motion-sensor"
deviceLabel: Matter Motion Sensor
deviceTypes:
- id: 0x0107 # Occupancy Sensor
deviceProfileName: matter-motion-battery
deviceProfileName: motion-battery
- id: "matter/motion-sensor/contact"
deviceLabel: Matter Motion/Contact Sensor
deviceTypes:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: matter-motion-battery
components:
- id: main
capabilities:
- id: motionSensor
version: 1
- id: battery
version: 1
- id: firmwareUpdate
version: 1
- id: refresh
version: 1
categories:
- name: MotionSensor
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: matter-motion-battery
name: motion-battery
components:
- id: main
capabilities:
Expand Down
14 changes: 14 additions & 0 deletions drivers/SmartThings/matter-sensor/profiles/motion-contact.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: motion-contact
components:
- id: main
capabilities:
- id: motionSensor
version: 1
- id: contactSensor
version: 1
- id: firmwareUpdate
version: 1
- id: refresh
version: 1
categories:
- name: MotionSensor
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: motion-illuminance-battery
components:
- id: main
capabilities:
- id: motionSensor
version: 1
- id: battery
version: 1
- id: illuminanceMeasurement
version: 1
- id: firmwareUpdate
version: 1
- id: refresh
version: 1
categories:
- name: MotionSensor
14 changes: 14 additions & 0 deletions drivers/SmartThings/matter-sensor/profiles/motion-illuminance.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: motion-illuminance
components:
- id: main
capabilities:
- id: motionSensor
version: 1
- id: illuminanceMeasurement
version: 1
- id: firmwareUpdate
version: 1
- id: refresh
version: 1
categories:
- name: MotionSensor
49 changes: 48 additions & 1 deletion drivers/SmartThings/matter-sensor/src/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,57 @@ local clusters = require "st.matter.clusters"
local MatterDriver = require "st.matter.driver"
local utils = require "st.utils"

local BATTERY_CHECKED = "__battery_checked"

local function check_for_battery(device)
local battery_eps = device:get_endpoints(clusters.PowerSource.ID, {feature_bitmap = clusters.PowerSource.types.PowerSourceFeature.BATTERY})
local profile_name = ""

if device:supports_capability(capabilities.motionSensor) then
profile_name = profile_name .. "-motion"
end

if device:supports_capability(capabilities.contactSensor) then
profile_name = profile_name .. "-contact"
end

if device:supports_capability(capabilities.illuminanceMeasurement) then
profile_name = profile_name .. "-illuminance"
end

if device:supports_capability(capabilities.temperatureMeasurement) then
profile_name = profile_name .. "-temperature"
end

if device:supports_capability(capabilities.relativeHumidityMeasurement) then
profile_name = profile_name .. "-humidity"
end

if #battery_eps > 0 then
profile_name = profile_name .. "-battery"
end

-- remove leading "-"
profile_name = string.sub(profile_name, 2)

device:try_update_metadata({profile = profile_name})
device:set_field(BATTERY_CHECKED, 1, {persist = true})
end

local function device_init(driver, device)
log.info("device init")
if not device:get_field(BATTERY_CHECKED) then
check_for_battery(device)
end
device:subscribe()
end

local function info_changed(driver, device, event, args)
if device.profile.id ~= args.old_st_store.profile.id then
device:subscribe()
end
end

local function illuminance_attr_handler(driver, device, ib, response)
local lux = math.floor(10 ^ ((ib.data.value - 1) / 10000))
device:emit_event_for_endpoint(ib.endpoint_id, capabilities.illuminanceMeasurement.illuminance(lux))
Expand Down Expand Up @@ -60,7 +106,8 @@ end

local matter_driver_template = {
lifecycle_handlers = {
init = device_init
init = device_init,
infoChanged = info_changed
},
matter_handlers = {
attr = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ end
local function test_init()
test.socket.matter:__expect_send({mock_device.id, subscribe_on_init(mock_device)})
test.mock_device.add_test_device(mock_device)
-- don't check the battery for this device because we are using the catch-all "sensor.yml" profile just for testing
mock_device:set_field("__battery_checked", 1, {persist = true})
end
test.set_test_init_function(test_init)

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,180 @@
-- Copyright 2023 SmartThings
--
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.

local test = require "integration_test"
local t_utils = require "integration_test.utils"
local clusters = require "st.matter.clusters"

local mock_device_humidity_battery = test.mock_device.build_test_matter_device({
profile = t_utils.get_profile_definition("humidity-battery.yml"),
manufacturer_info = {
vendor_id = 0x0000,
product_id = 0x0000,
},
endpoints = {
{
endpoint_id = 0,
clusters = {
{cluster_id = clusters.Basic.ID, cluster_type = "SERVER"},
},
device_types = {
device_type_id = 0x0016, device_type_revision = 1, -- RootNode
}
},
{
endpoint_id = 1,
clusters = {
{cluster_id = clusters.RelativeHumidityMeasurement.ID, cluster_type = "SERVER"},
}
},
{
endpoint_id = 2,
clusters = {
{cluster_id = clusters.PowerSource.ID, cluster_type = "SERVER", feature_map = 2},
}
}
}
})

local mock_device_humidity_no_battery = test.mock_device.build_test_matter_device({
profile = t_utils.get_profile_definition("humidity-battery.yml"),
manufacturer_info = {
vendor_id = 0x0000,
product_id = 0x0000,
},
endpoints = {
{
endpoint_id = 0,
clusters = {
{cluster_id = clusters.Basic.ID, cluster_type = "SERVER"},
},
device_types = {
device_type_id = 0x0016, device_type_revision = 1, -- RootNode
}
},
{
endpoint_id = 1,
clusters = {
{cluster_id = clusters.RelativeHumidityMeasurement.ID, cluster_type = "SERVER"},
}
}
}
})

local mock_device_temp_humidity = test.mock_device.build_test_matter_device({
profile = t_utils.get_profile_definition("temperature-humidity.yml"),
manufacturer_info = {
vendor_id = 0x0000,
product_id = 0x0000,
},
endpoints = {
{
endpoint_id = 0,
clusters = {
{cluster_id = clusters.Basic.ID, cluster_type = "SERVER"},
},
device_types = {
device_type_id = 0x0016, device_type_revision = 1, -- RootNode
}
},
{
endpoint_id = 1,
clusters = {
{cluster_id = clusters.RelativeHumidityMeasurement.ID, cluster_type = "SERVER"},
}
},
{
endpoint_id = 2,
clusters = {
{cluster_id = clusters.TemperatureMeasurement.ID, cluster_type = "BOTH"},
}
}
}
})

local cluster_subscribe_list_humidity_battery = {
clusters.RelativeHumidityMeasurement.attributes.MeasuredValue,
clusters.PowerSource.attributes.BatPercentRemaining
}

local cluster_subscribe_list_humidity_no_battery = {
clusters.RelativeHumidityMeasurement.attributes.MeasuredValue
}

local cluster_subscribe_list_temp_humidity = {
clusters.RelativeHumidityMeasurement.attributes.MeasuredValue,
clusters.TemperatureMeasurement.attributes.MeasuredValue
}

local function test_init_humidity_battery()
local subscribe_request_humidity_battery = cluster_subscribe_list_humidity_battery[1]:subscribe(mock_device_humidity_battery)
for i, cluster in ipairs(cluster_subscribe_list_humidity_battery) do
if i > 1 then
subscribe_request_humidity_battery:merge(cluster:subscribe(mock_device_humidity_battery))
end
end

test.socket.matter:__expect_send({mock_device_humidity_battery.id, subscribe_request_humidity_battery})
test.mock_device.add_test_device(mock_device_humidity_battery)
mock_device_humidity_battery:expect_metadata_update({ profile = "humidity-battery" })
end

local function test_init_humidity_no_battery()
local subscribe_request_humidity_no_battery = cluster_subscribe_list_humidity_no_battery[1]:subscribe(mock_device_humidity_no_battery)
for i, cluster in ipairs(cluster_subscribe_list_humidity_no_battery) do
if i > 1 then
subscribe_request_humidity_no_battery:merge(cluster:subscribe(mock_device_humidity_no_battery))
end
end

test.socket.matter:__expect_send({mock_device_humidity_no_battery.id, subscribe_request_humidity_no_battery})
test.mock_device.add_test_device(mock_device_humidity_no_battery)
mock_device_humidity_no_battery:expect_metadata_update({ profile = "humidity" })
end

local function test_init_temp_humidity()
local subscribe_request_temp_humidity = cluster_subscribe_list_temp_humidity[1]:subscribe(mock_device_temp_humidity)
for i, cluster in ipairs(cluster_subscribe_list_temp_humidity) do
if i > 1 then
subscribe_request_temp_humidity:merge(cluster:subscribe(mock_device_temp_humidity))
end
end

test.socket.matter:__expect_send({mock_device_temp_humidity.id, subscribe_request_temp_humidity})
test.mock_device.add_test_device(mock_device_temp_humidity)
mock_device_temp_humidity:expect_metadata_update({ profile = "temperature-humidity" })
end

test.register_coroutine_test(
"Test profile change on init for humidity sensor with battery",
function()
end,
{ test_init = test_init_humidity_battery }
)

test.register_coroutine_test(
"Test profile change on init for humidity sensor without battery",
function()
end,
{ test_init = test_init_humidity_no_battery }
)

test.register_coroutine_test(
"Test profile change on init for temperature-humidity sensor",
function()
end,
{ test_init = test_init_temp_humidity }
)

test.run_registered_tests()
16 changes: 8 additions & 8 deletions drivers/SmartThings/matter-switch/fingerprints.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,31 @@ matterManufacturer:
deviceLabel: Eve Energy
vendorId: 0x130A
productId: 0x53
deviceProfileName: plug-binary
deviceProfileName: power-energy-powerConsumption
- id: "Eve/Energy/Europe"
deviceLabel: Eve Energy
vendorId: 0x130A
productId: 0x50
deviceProfileName: plug-binary
deviceProfileName: power-energy-powerConsumption
- id: "Eve/Energy/U.K."
deviceLabel: Eve Energy
vendorId: 0x130A
productId: 0x54
deviceProfileName: plug-binary
deviceProfileName: power-energy-powerConsumption
- id: "Eve/Energy/Australia"
deviceLabel: Eve Energy
vendorId: 0x130A
productId: 0x5E
deviceProfileName: plug-binary
deviceProfileName: power-energy-powerConsumption

#GE
- id: "GELightingSavant/FullColor/Bulb"
deviceLabel: GELighting Savant Full Color Bulb WiFi
- id: "GELightingSavant/Bulb/A19"
deviceLabel: Cync Full Color A19
vendorId: 0x1339
productId: 0x89
deviceProfileName: light-color-level-2000K-7000K
- id: "GELightingSavant/Onoff/Plug"
deviceLabel: GELighting Savant OnOff Plug WiFi
- id: "GELightingSavant/Plug/Indoor"
deviceLabel: Cync Indoor Plug
vendorId: 0x1339
productId: 0xAC
deviceProfileName: plug-binary
Expand Down
Loading

0 comments on commit 01cfa70

Please sign in to comment.