Skip to content

Commit

Permalink
feat: added 2 new thermostat capabilities
Browse files Browse the repository at this point in the history
`thermostatMode`
`thermostatOperatingState`

resolves #2
  • Loading branch information
w35l3y committed Apr 1, 2023
1 parent f4f871a commit 5c89104
Show file tree
Hide file tree
Showing 13 changed files with 229 additions and 5 deletions.
8 changes: 8 additions & 0 deletions personal-tuya-devices/models/TS0601/_TZE200_4hbx5cvx.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ datapoints:
command: switch
base:
group: 1
- id: 2
command: thermostatMode
base:
group: 1
- id: 16
command: thermostatHeatingSetpoint
base:
Expand All @@ -17,6 +21,10 @@ datapoints:
base:
group: 1
rate: 100
- id: 104
command: thermostatOperatingState
base:
group: 1
- id: 101
command: temperatureMeasurement
base:
Expand Down
38 changes: 38 additions & 0 deletions personal-tuya-devices/profiles/child-thermostatMode.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# https://developer.smartthings.com/docs/devices/device-profiles#categories
# https://community.smartthings.com/t/change-icons-in-new-app/184190/25?u=w35l3y
name: "child-thermostatMode-v1"
components:
- id: main
label: Mode
capabilities:
- id: thermostatMode
version: 1
config:
values:
- key: thermostatMode.value #read
enabledValues:
- manual
- heat
- away
- auto
- eco
- custom
- key: setThermostatMode #write
enabledValues:
- manual
- heat
- away
- auto
- eco
- id: refresh
version: 1
categories:
- name: Thermostat
metadata:
deviceType: Thermostat
ocfDeviceType: oic.d.thermostat
deviceTypeId: Thermostat
mnmn: SmartThingsCommunity
owner:
ownerType: USER
ownerId: ea35e8c8-3aef-2f72-958b-e3ad10644043
21 changes: 21 additions & 0 deletions personal-tuya-devices/profiles/child-thermostatOperatingState.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# https://developer.smartthings.com/docs/devices/device-profiles#categories
# https://community.smartthings.com/t/change-icons-in-new-app/184190/25?u=w35l3y
name: "child-thermostatOperatingState-v1"
components:
- id: main
label: Operating State
capabilities:
- id: thermostatOperatingState
version: 1
- id: refresh
version: 1
categories:
- name: Thermostat
metadata:
deviceType: Thermostat
ocfDeviceType: oic.d.thermostat
deviceTypeId: Thermostat
mnmn: SmartThingsCommunity
owner:
ownerType: USER
ownerId: ea35e8c8-3aef-2f72-958b-e3ad10644043
16 changes: 16 additions & 0 deletions personal-tuya-devices/profiles/generic-ef00-v1.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,22 @@ preferences:
definition:
stringType: text
default: ""
- name: thermostatModeDatapoints
title: Thermostat Mode
description: List of datapoints used for thermostat modes (comma-separated)
required: true
preferenceType: string
definition:
stringType: text
default: ""
- name: thermostatOperDatapoints
title: Thermostat Operating State
description: List of datapoints used for thermostat operating states (comma-separated)
required: true
preferenceType: string
definition:
stringType: text
default: ""
- name: tvocMeasuremenDatapoints
title: VOC sensors
description: List of datapoints used for VOC sensors (comma-separated)
Expand Down
21 changes: 21 additions & 0 deletions personal-tuya-devices/profiles/normal-thermostat-v3.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,31 @@ components:
capabilities:
- id: switch
version: 1
- id: thermostatMode
version: 1
config:
values:
- key: thermostatMode.value #read
enabledValues:
- manual
- heat
- away
- auto
- eco
- custom
- key: setThermostatMode #write
enabledValues:
- manual
- heat
- away
- auto
- eco
- id: temperatureMeasurement
version: 1
- id: thermostatHeatingSetpoint
version: 1
- id: thermostatOperatingState
version: 1
- id: signalStrength
version: 1
- id: refresh
Expand Down
27 changes: 27 additions & 0 deletions personal-tuya-devices/src/commands.lua
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,33 @@ local defaults = {
return math.floor(100 * to_number(value) / get_value(pref[self.rate_name], self.rate))
end,
},
thermostatMode = {
capability = "thermostatMode",
attribute = "thermostatMode",
command_arg = "mode",
supported_values = { "manual", "heat", "away", "auto", "eco" },
to_zigbee = function (self, value, device)
for i, v in ipairs(self.supported_values) do
if v == value then
return data_types.Enum8(i - 1)
end
end
log.warn("thermostatMode : unsupported value", value)
return data_types.Enum8(0)
end,
from_zigbee = function (self, value, device)
local v = to_number(value)
return self.supported_values[1 + v] or "custom"
end
},
thermostatOperatingState = {
capability = "thermostatOperatingState",
attribute = "thermostatOperatingState",
from_zigbee = function (self, value, device)
local v = to_number(value)
return v == 0 and "idle" or "heating"
end
},
tvocMeasurement = {
capability = "tvocMeasurement",
attribute = "tvocLevel",
Expand Down
7 changes: 6 additions & 1 deletion personal-tuya-devices/src/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,18 @@ local template = {
capabilities.refresh,
},
zigbee_handlers = {
global = {
[zcl_clusters.TuyaEF00.ID] = {
[zcl_global_commands.DEFAULT_RESPONSE_ID] = function() end,
},
},
attr = {
[zcl_clusters.Basic.ID] = {
[zcl_clusters.Basic.attributes.ZCLVersion.ID] = function() end,
},
},
fallback = function (driver, device, zb_rx)
log.debug("Default fallback", zb_rx:pretty_print())
log.debug("FALLBACK", zb_rx:pretty_print())
end,
},
health_check = true,
Expand Down
1 change: 1 addition & 0 deletions personal-tuya-devices/src/sub_drivers/genericEF00/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ local template = {
capabilities.switchLevel,
capabilities.thermostatCoolingSetpoint,
capabilities.thermostatHeatingSetpoint,
capabilities.thermostatMode,
capabilities.valve,
capabilities.windowShade,
capabilities.windowShadeLevel,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ local template = {
capabilities.switchLevel,
capabilities.thermostatCoolingSetpoint,
capabilities.thermostatHeatingSetpoint,
capabilities.thermostatMode,
capabilities.valve,
capabilities.windowShade,
capabilities.windowShadeLevel,
Expand Down
82 changes: 82 additions & 0 deletions personal-tuya-devices/src/test/generic-ef00-v1.lua
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,18 @@ local mock_child_32 = test.mock_device.build_test_child_device({
parent_assigned_child_key = string.format("%02X", 32)
})

local mock_child_33 = test.mock_device.build_test_child_device({
profile = t_utils.get_profile_definition("child-thermostatMode-v1.yaml"),
parent_device_id = mock_parent_device.id,
parent_assigned_child_key = string.format("%02X", 33)
})

local mock_child_34 = test.mock_device.build_test_child_device({
profile = t_utils.get_profile_definition("child-thermostatOperatingState-v1.yaml"),
parent_device_id = mock_parent_device.id,
parent_assigned_child_key = string.format("%02X", 34)
})

local test_init_parent = function ()
test.mock_device.add_test_device(mock_parent_device)

Expand Down Expand Up @@ -280,6 +292,8 @@ local test_init = function ()
batteryDatapoints = "30",
thermostatCoolDatapoints = "31",
thermostatHeatDatapoints = "32",
thermostatModeDatapoints = "33",
thermostatOperDatapoints = "34",
}
}))

Expand Down Expand Up @@ -315,6 +329,8 @@ local test_init = function ()
test.mock_device.add_test_device(mock_child_30)
test.mock_device.add_test_device(mock_child_31)
test.mock_device.add_test_device(mock_child_32)
test.mock_device.add_test_device(mock_child_33)
test.mock_device.add_test_device(mock_child_34)
end

test.register_message_test("device_lifecycle added", {
Expand Down Expand Up @@ -1112,3 +1128,69 @@ test.register_message_test(
}
)

test.register_message_test(
"thermostatMode",
{
{
channel = "capability",
direction = "receive",
message = { mock_child_33.id, { capability = "thermostatMode", component = "main", command = "setThermostatMode", args = { mode = "heat" } } }
},
{
channel = "zigbee",
direction = "send",
message = { mock_parent_device.id, zcl_clusters.TuyaEF00.commands.DataRequest(mock_parent_device, 33, data_types.Enum8(1)) }
},
{
channel = "zigbee",
direction = "receive",
message = { mock_parent_device.id, zcl_clusters.TuyaEF00.commands.DataReport:build_test_rx(mock_parent_device, 33, data_types.Enum8(2)) }
},
{
channel = "capability",
direction = "send",
message = mock_child_33:generate_test_message("main", capabilities.thermostatMode.thermostatMode("away"))
},
{
channel = "zigbee",
direction = "receive",
message = { mock_parent_device.id, zcl_clusters.TuyaEF00.commands.DataReport:build_test_rx(mock_parent_device, 33, data_types.Enum8(0xFF)) }
},
{
channel = "capability",
direction = "send",
message = mock_child_33:generate_test_message("main", capabilities.thermostatMode.thermostatMode("custom"))
},
}, {
test_init = test_init
}
)

test.register_message_test(
"thermostatOperatingState",
{
{
channel = "zigbee",
direction = "receive",
message = { mock_parent_device.id, zcl_clusters.TuyaEF00.commands.DataReport:build_test_rx(mock_parent_device, 34, data_types.Boolean(true)) }
},
{
channel = "capability",
direction = "send",
message = mock_child_34:generate_test_message("main", capabilities.thermostatOperatingState.thermostatOperatingState("heating"))
},
{
channel = "zigbee",
direction = "receive",
message = { mock_parent_device.id, zcl_clusters.TuyaEF00.commands.DataReport:build_test_rx(mock_parent_device, 34, data_types.Boolean(false)) }
},
{
channel = "capability",
direction = "send",
message = mock_child_34:generate_test_message("main", capabilities.thermostatOperatingState.thermostatOperatingState("idle"))
},
}, {
test_init = test_init
}
)

4 changes: 2 additions & 2 deletions personal-tuya-devices/src/tuyaEF00_defaults.lua
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,11 @@ end

function defaults.command_gatestatus_handler(driver, device, zb_rx)
device:send(zcl_clusters.TuyaEF00.commands.GatewayStatusResponse(device, zb_rx.body.zcl_body.data.value))
log.info("GatewayStatusRequest", zb_rx:pretty_print())
-- log.info("GatewayStatusRequest", zb_rx:pretty_print())
end

function defaults.fallback_handler (driver, device, zb_rx)
log.debug("Default fallback", zb_rx:pretty_print())
log.debug("DEFAULT FALLBACK", zb_rx:pretty_print())
end

function defaults.command_response_handler(datapoints)
Expand Down
6 changes: 5 additions & 1 deletion personal-tuya-devices/src/tuyaEF00_generic_defaults.lua
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ local datapoint_types_to_fn = {
temperatureMeaDatapoints = commands.temperatureMeasurement,
thermostatCoolDatapoints = commands.thermostatCoolingSetpoint,
thermostatHeatDatapoints = commands.thermostatHeatingSetpoint,
thermostatModeDatapoints = commands.thermostatMode,
thermostatOperDatapoints = commands.thermostatOperatingState,
tvocMeasuremenDatapoints = commands.tvocMeasurement,
valveDatapoints = commands.valve,
voltageMeasureDatapoints = commands.voltageMeasurement,
Expand Down Expand Up @@ -74,6 +76,8 @@ local child_types_to_profile = {
temperatureMeaDatapoints = "child-temperatureMeasurement-v1",
thermostatCoolDatapoints = "child-thermostatCoolingSetpoint-v1",
thermostatHeatDatapoints = "child-thermostatHeatingSetpoint-v1",
thermostatModeDatapoints = "child-thermostatMode-v1",
thermostatOperDatapoints = "child-thermostatOperatingState-v1",
tvocMeasuremenDatapoints = "child-tvocMeasurement-v1",
valveDatapoints = "child-valve-v1",
voltageMeasureDatapoints = "child-voltageMeasurement-v1",
Expand Down Expand Up @@ -188,7 +192,7 @@ local defaults = {
command_synctime_handler = tuyaEF00_defaults.command_synctime_handler,
command_gatestatus_handler = tuyaEF00_defaults.command_gatestatus_handler,
fallback_handler = function (driver, device, zb_rx)
log.debug("Generic fallback", zb_rx:pretty_print())
log.debug("GENERIC FALLBACK", zb_rx:pretty_print())
end,
}

Expand Down
2 changes: 1 addition & 1 deletion personal-tuya-devices/src/tuyaEF00_model_defaults.lua
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ local defaults = {
command_synctime_handler = tuyaEF00_defaults.command_synctime_handler,
command_gatestatus_handler = tuyaEF00_defaults.command_gatestatus_handler,
fallback_handler = function (driver, device, zb_rx)
log.debug("Model fallback", zb_rx:pretty_print())
log.debug("MODEL FALLBACK", zb_rx:pretty_print())
end,
}

Expand Down

0 comments on commit 5c89104

Please sign in to comment.