Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Matter 1.2 clusters directly to drivers #1390

Merged
merged 3 commits into from
Jun 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,39 +3,39 @@ components:
- id: main
label: Main
capabilities:
- id: mode # Refrigerator And Temperature Controlled Cabinet Mode
ctowns marked this conversation as resolved.
Show resolved Hide resolved
- id: mode
version: 1
- id: contactSensor # Refrigerator Alarm
- id: contactSensor
version: 1
- id: firmwareUpdate
version: 1
- id: refresh
version: 1
categories:
- name: Refrigerator
- id: refrigerator # First endpoint
- id: refrigerator
label: Refrigerator
capabilities:
- id: mode # Refrigerator And Temperature Controlled Cabinet Mode
- id: mode
version: 1
- id: temperatureSetpoint # Temperature Control / TN
- id: temperatureSetpoint
version: 1
config:
values:
- key: "temperatureSetpoint.value"
range: [ 0, 100 ]
- id: temperatureMeasurement # Temperature Measurement
- id: temperatureMeasurement
version: 1
categories:
- name: Refrigerator
- id: freezer # Second endpoint
- id: freezer
label: Freezer
capabilities:
- id: mode # Refrigerator And Temperature Controlled Cabinet Mode
- id: mode
version: 1
- id: temperatureLevel # Temperature Control / TL
- id: temperatureLevel
version: 1
- id: temperatureMeasurement # Temperature Measurement
- id: temperatureMeasurement
version: 1
categories:
- name: Refrigerator
90 changes: 90 additions & 0 deletions drivers/SmartThings/matter-appliance/src/DishwasherAlarm/init.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
local cluster_base = require "st.matter.cluster_base"
local DishwasherAlarmServerAttributes = require "DishwasherAlarm.server.attributes"
local DishwasherAlarmTypes = require "DishwasherAlarm.types"

local DishwasherAlarm = {}

DishwasherAlarm.ID = 0x005D
DishwasherAlarm.NAME = "DishwasherAlarm"
DishwasherAlarm.server = {}
DishwasherAlarm.client = {}
DishwasherAlarm.server.attributes = DishwasherAlarmServerAttributes:set_parent_cluster(DishwasherAlarm)
DishwasherAlarm.types = DishwasherAlarmTypes

function DishwasherAlarm:get_attribute_by_id(attr_id)
local attr_id_map = {
[0x0000] = "Mask",
[0x0001] = "Latch",
[0x0002] = "State",
[0x0003] = "Supported",
[0xFFF9] = "AcceptedCommandList",
[0xFFFA] = "EventList",
[0xFFFB] = "AttributeList",
}
local attr_name = attr_id_map[attr_id]
if attr_name ~= nil then
return self.attributes[attr_name]
end
return nil
end

function DishwasherAlarm:get_server_command_by_id(command_id)
local server_id_map = {
[0x0000] = "Reset",
[0x0001] = "ModifyEnabledAlarms",
}
if server_id_map[command_id] ~= nil then
return self.server.commands[server_id_map[command_id]]
end
return nil
end

function DishwasherAlarm:get_event_by_id(event_id)
local event_id_map = {
[0x0000] = "Notify",
}
if event_id_map[event_id] ~= nil then
return self.server.events[event_id_map[event_id]]
end
return nil
end

DishwasherAlarm.attribute_direction_map = {
["Mask"] = "server",
["Latch"] = "server",
["State"] = "server",
["Supported"] = "server",
["AcceptedCommandList"] = "server",
["EventList"] = "server",
["AttributeList"] = "server",
}

DishwasherAlarm.command_direction_map = {
["Reset"] = "server",
["ModifyEnabledAlarms"] = "server",
}

DishwasherAlarm.FeatureMap = DishwasherAlarm.types.Feature

function DishwasherAlarm.are_features_supported(feature, feature_map)
if (DishwasherAlarm.FeatureMap.bits_are_valid(feature)) then
return (feature & feature_map) == feature
end
return false
end

local attribute_helper_mt = {}
attribute_helper_mt.__index = function(self, key)
local direction = DishwasherAlarm.attribute_direction_map[key]
if direction == nil then
error(string.format("Referenced unknown attribute %s on cluster %s", key, DishwasherAlarm.NAME))
end
return DishwasherAlarm[direction].attributes[key]
end
DishwasherAlarm.attributes = {}
setmetatable(DishwasherAlarm.attributes, attribute_helper_mt)

setmetatable(DishwasherAlarm, {__index = cluster_base})

return DishwasherAlarm

Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
local cluster_base = require "st.matter.cluster_base"
local data_types = require "st.matter.data_types"
local TLVParser = require "st.matter.TLV.TLVParser"

local AcceptedCommandList = {
ID = 0xFFF9,
NAME = "AcceptedCommandList",
base_type = require "st.matter.data_types.Array",
element_type = require "st.matter.data_types.Uint32",
}

function AcceptedCommandList:augment_type(data_type_obj)
for i, v in ipairs(data_type_obj.elements) do
data_type_obj.elements[i] = data_types.validate_or_build_type(v, AcceptedCommandList.element_type)
end
end

function AcceptedCommandList:new_value(...)
local o = self.base_type(table.unpack({...}))

return o
end

function AcceptedCommandList:read(device, endpoint_id)
return cluster_base.read(
device,
endpoint_id,
self._cluster.ID,
self.ID,
nil
)
end

function AcceptedCommandList:subscribe(device, endpoint_id)
return cluster_base.subscribe(
device,
endpoint_id,
self._cluster.ID,
self.ID,
nil
)
end

function AcceptedCommandList:set_parent_cluster(cluster)
self._cluster = cluster
return self
end

function AcceptedCommandList:build_test_report_data(
device,
endpoint_id,
value,
status
)
local data = data_types.validate_or_build_type(value, self.base_type)

return cluster_base.build_test_report_data(
device,
endpoint_id,
self._cluster.ID,
self.ID,
data,
status
)
end

function AcceptedCommandList:deserialize(tlv_buf)
local data = TLVParser.decode_tlv(tlv_buf)

return data
end

setmetatable(AcceptedCommandList, {__call = AcceptedCommandList.new_value, __index = AcceptedCommandList.base_type})
return AcceptedCommandList

Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
local cluster_base = require "st.matter.cluster_base"
local data_types = require "st.matter.data_types"
local TLVParser = require "st.matter.TLV.TLVParser"

local Mask = {
ID = 0x0000,
NAME = "Mask",
base_type = require "DishwasherAlarm.types.AlarmMap",
}

function Mask:new_value(...)
local o = self.base_type(table.unpack({...}))
self:augment_type(o)
return o
end

function Mask:read(device, endpoint_id)
return cluster_base.read(
device,
endpoint_id,
self._cluster.ID,
self.ID,
nil
)
end

function Mask:subscribe(device, endpoint_id)
return cluster_base.subscribe(
device,
endpoint_id,
self._cluster.ID,
self.ID,
nil
)
end

function Mask:set_parent_cluster(cluster)
self._cluster = cluster
return self
end

function Mask:build_test_report_data(
device,
endpoint_id,
value,
status
)
local data = data_types.validate_or_build_type(value, self.base_type)
self:augment_type(data)
return cluster_base.build_test_report_data(
device,
endpoint_id,
self._cluster.ID,
self.ID,
data,
status
)
end

function Mask:deserialize(tlv_buf)
local data = TLVParser.decode_tlv(tlv_buf)
self:augment_type(data)
return data
end

setmetatable(Mask, {__call = Mask.new_value, __index = Mask.base_type})
return Mask

Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
local cluster_base = require "st.matter.cluster_base"
local data_types = require "st.matter.data_types"
local TLVParser = require "st.matter.TLV.TLVParser"

local State = {
ID = 0x0002,
NAME = "State",
base_type = require "DishwasherAlarm.types.AlarmMap",
}

function State:new_value(...)
local o = self.base_type(table.unpack({...}))
self:augment_type(o)
return o
end

function State:read(device, endpoint_id)
return cluster_base.read(
device,
endpoint_id,
self._cluster.ID,
self.ID,
nil
)
end

function State:subscribe(device, endpoint_id)
return cluster_base.subscribe(
device,
endpoint_id,
self._cluster.ID,
self.ID,
nil
)
end

function State:set_parent_cluster(cluster)
self._cluster = cluster
return self
end

function State:build_test_report_data(
device,
endpoint_id,
value,
status
)
local data = data_types.validate_or_build_type(value, self.base_type)
self:augment_type(data)
return cluster_base.build_test_report_data(
device,
endpoint_id,
self._cluster.ID,
self.ID,
data,
status
)
end

function State:deserialize(tlv_buf)
local data = TLVParser.decode_tlv(tlv_buf)
self:augment_type(data)
return data
end

setmetatable(State, {__call = State.new_value, __index = State.base_type})
return State

Loading
Loading