Skip to content

Commit

Permalink
Check sub driver using device type id
Browse files Browse the repository at this point in the history
Signed-off-by: Youngho Yoon <[email protected]>
  • Loading branch information
yhoyoon authored and samadDotDev committed Jan 30, 2024
1 parent 23ea144 commit e0696a6
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 25 deletions.
22 changes: 22 additions & 0 deletions drivers/SmartThings/matter-appliance/src/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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] = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand All @@ -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)
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit e0696a6

Please sign in to comment.