From e0696a630003d01105715ca0537aa1b8f2cc2510 Mon Sep 17 00:00:00 2001 From: Youngho Yoon <34558998+yhoyoon@users.noreply.github.com> Date: Thu, 25 Jan 2024 20:05:49 +0900 Subject: [PATCH] Check sub driver using device type id Signed-off-by: Youngho Yoon <34558998+yhoyoon@users.noreply.github.com> --- .../SmartThings/matter-appliance/src/init.lua | 22 +++++++++++++++++++ .../src/matter-dishwasher/init.lua | 17 ++++++++------ .../src/matter-laundry-washer/init.lua | 16 +++++++++----- .../src/matter-refrigerator/init.lua | 21 ++++++++---------- 4 files changed, 51 insertions(+), 25 deletions(-) diff --git a/drivers/SmartThings/matter-appliance/src/init.lua b/drivers/SmartThings/matter-appliance/src/init.lua index fcfe21c713..5f8340d76f 100644 --- a/drivers/SmartThings/matter-appliance/src/init.lua +++ b/drivers/SmartThings/matter-appliance/src/init.lua @@ -23,6 +23,10 @@ local temperatureLevelId = "spacewonder52282.temperatureLevel" local temperatureLevel = capabilities[temperatureLevelId] local operationalStateId = "spacewonder52282.operationalState1" local operationalState = capabilities[operationalStateId] +local laundryWasherModeId = "spacewonder52282.laundryWasherMode" +local laundryWasherMode = capabilities[laundryWasherModeId] +local refrigeratorAndTccModeId = "spacewonder52282.refrigeratorAndTccMode" +local refrigeratorAndTccMode = capabilities[refrigeratorAndTccModeId] local function device_init(driver, device) device:subscribe() @@ -132,6 +136,24 @@ local matter_driver_template = { [operationalStateId] = { clusters.OperationalState.attributes.OperationalState, }, + [capabilities.mode.ID] = { + clusters.DishwasherMode.attributes.SupportedModes, + clusters.DishwasherMode.attributes.CurrentMode, + }, + [laundryWasherModeId] = { + clusters.LaundryWasherMode.attributes.SupportedModes, + clusters.LaundryWasherMode.attributes.CurrentMode, + }, + [refrigeratorAndTccModeId] = { + clusters.RefrigeratorAndTemperatureControlledCabinetMode.attributes.SupportedModes, + clusters.RefrigeratorAndTemperatureControlledCabinetMode.attributes.CurrentMode, + }, + [capabilities.contactSensor.ID] = { + clusters.RefrigeratorAlarm.attributes.State + }, + [capabilities.temperatureMeasurement.ID] = { + clusters.TemperatureMeasurement.attributes.MeasuredValue + }, }, capability_handlers = { [capabilities.switch.ID] = { diff --git a/drivers/SmartThings/matter-appliance/src/matter-dishwasher/init.lua b/drivers/SmartThings/matter-appliance/src/matter-dishwasher/init.lua index b186339092..96bb6bc015 100644 --- a/drivers/SmartThings/matter-appliance/src/matter-dishwasher/init.lua +++ b/drivers/SmartThings/matter-appliance/src/matter-dishwasher/init.lua @@ -19,6 +19,8 @@ local clusters = require "st.matter.clusters" local log = require "log" local utils = require "st.utils" +local DISHWASHER_DEVICE_TYPE_ID = 0x0075 + local dishwasherModeSupportedModes = {} local function device_init(driver, device) @@ -27,7 +29,14 @@ end -- Matter Handlers -- local function is_matter_dishwasher(opts, driver, device) - return device:supports_capability_by_id(capabilities.mode.ID) + for _, ep in ipairs(device.endpoints) do + for _, dt in ipairs(ep.device_types) do + if dt.device_type_id == DISHWASHER_DEVICE_TYPE_ID then + return true + end + end + end + return false end local function dishwasher_supported_modes_attr_handler(driver, device, ib, response) @@ -78,12 +87,6 @@ local matter_dishwasher_handler = { }, } }, - subscribed_attributes = { - [capabilities.mode.ID] = { - clusters.DishwasherMode.attributes.SupportedModes, - clusters.DishwasherMode.attributes.CurrentMode, - }, - }, capability_handlers = { [capabilities.mode.ID] = { [capabilities.mode.commands.setMode.NAME] = handle_dishwasher_mode, diff --git a/drivers/SmartThings/matter-appliance/src/matter-laundry-washer/init.lua b/drivers/SmartThings/matter-appliance/src/matter-laundry-washer/init.lua index 15f39836da..08d75af518 100644 --- a/drivers/SmartThings/matter-appliance/src/matter-laundry-washer/init.lua +++ b/drivers/SmartThings/matter-appliance/src/matter-laundry-washer/init.lua @@ -19,6 +19,8 @@ local clusters = require "st.matter.clusters" local log = require "log" local utils = require "st.utils" +local LAUNDRY_WASHER_DEVICE_TYPE_ID = 0x0073 + local laundryWasherModeId = "spacewonder52282.laundryWasherMode" local laundryWasherMode = capabilities[laundryWasherModeId] @@ -28,7 +30,14 @@ end -- Matter Handlers -- local function is_matter_laundry_washer(opts, driver, device) - return device:supports_capability_by_id(laundryWasherModeId) + for _, ep in ipairs(device.endpoints) do + for _, dt in ipairs(ep.device_types) do + if dt.device_type_id == LAUNDRY_WASHER_DEVICE_TYPE_ID then + return true + end + end + end + return false end local function laundry_washer_mode_attr_handler(driver, device, ib, response) @@ -79,11 +88,6 @@ local matter_laundry_washer_handler = { }, } }, - subscribed_attributes = { - [laundryWasherModeId] = { - clusters.LaundryWasherMode.attributes.CurrentMode, - }, - }, capability_handlers = { [laundryWasherModeId] = { [laundryWasherMode.commands.setLaundryWasherMode.NAME] = handle_laundry_washer_mode, diff --git a/drivers/SmartThings/matter-appliance/src/matter-refrigerator/init.lua b/drivers/SmartThings/matter-appliance/src/matter-refrigerator/init.lua index 92a26bfdaa..13e5a55eeb 100644 --- a/drivers/SmartThings/matter-appliance/src/matter-refrigerator/init.lua +++ b/drivers/SmartThings/matter-appliance/src/matter-refrigerator/init.lua @@ -19,6 +19,7 @@ local clusters = require "st.matter.clusters" local log = require "log" local utils = require "st.utils" +local REFRIGERATOR_DEVICE_TYPE_ID = 0x0070 local ENDPOINT_TO_COMPONENT_MAP = "__endpoint_to_component" local refrigeratorAndTccModeId = "spacewonder52282.refrigeratorAndTccMode" @@ -58,7 +59,14 @@ end -- Matter Handlers -- local function is_matter_refrigerator(opts, driver, device) - return device:supports_capability_by_id(refrigeratorAndTccModeId) + for _, ep in ipairs(device.endpoints) do + for _, dt in ipairs(ep.device_types) do + if dt.device_type_id == REFRIGERATOR_DEVICE_TYPE_ID then + return true + end + end + end + return false end local function refrigerator_tcc_mode_attr_handler(driver, device, ib, response) @@ -130,17 +138,6 @@ local matter_refrigerator_handler = { }, } }, - subscribed_attributes = { - [refrigeratorAndTccModeId] = { - clusters.RefrigeratorAndTemperatureControlledCabinetMode.attributes.CurrentMode, - }, - [capabilities.contactSensor.ID] = { - clusters.RefrigeratorAlarm.attributes.State - }, - [capabilities.temperatureMeasurement.ID] = { - clusters.TemperatureMeasurement.attributes.MeasuredValue - }, - }, capability_handlers = { [refrigeratorAndTccModeId] = { [refrigeratorAndTccMode.commands.setRefrigeratorAndTccMode.NAME] = handle_refrigerator_tcc_mode,