From 47c2da2216688ff9d5c84ab787592bf65380e54a Mon Sep 17 00:00:00 2001 From: thinkaName <962679819@qq.com> Date: Fri, 15 Nov 2024 13:56:07 +0800 Subject: [PATCH] add laisiao bathroom heater --- .../zigbee-switch/fingerprints.yml | 5 ++ .../switch-smart-bath-heater-laisiao.yml | 62 ++++++++++++++ .../SmartThings/zigbee-switch/src/init.lua | 3 +- .../zigbee-switch/src/laisiao/init.lua | 83 +++++++++++++++++++ tools/localizations/cn.csv | 1 + 5 files changed, 153 insertions(+), 1 deletion(-) create mode 100755 drivers/SmartThings/zigbee-switch/profiles/switch-smart-bath-heater-laisiao.yml create mode 100755 drivers/SmartThings/zigbee-switch/src/laisiao/init.lua diff --git a/drivers/SmartThings/zigbee-switch/fingerprints.yml b/drivers/SmartThings/zigbee-switch/fingerprints.yml index ffd5c26971..ab91e42bbc 100644 --- a/drivers/SmartThings/zigbee-switch/fingerprints.yml +++ b/drivers/SmartThings/zigbee-switch/fingerprints.yml @@ -2293,6 +2293,11 @@ zigbeeManufacturer: manufacturer: Insta GmbH model: NEXENTRO Dimming Actuator deviceProfileName: on-off-level + - id: "LAISIAO/BATH" + deviceLabel: Laisiao Bathroom Heater + manufacturer: LAISIAO + model: yuba + deviceProfileName: switch-smart-bath-heater-laisiao zigbeeGeneric: - id: "genericSwitch" deviceLabel: Zigbee Switch diff --git a/drivers/SmartThings/zigbee-switch/profiles/switch-smart-bath-heater-laisiao.yml b/drivers/SmartThings/zigbee-switch/profiles/switch-smart-bath-heater-laisiao.yml new file mode 100755 index 0000000000..e75b167ddf --- /dev/null +++ b/drivers/SmartThings/zigbee-switch/profiles/switch-smart-bath-heater-laisiao.yml @@ -0,0 +1,62 @@ +name: switch-smart-bath-heater-laisiao +components: + - id: main + label: "待机" + capabilities: + - id: switch + version: 1 + - id: firmwareUpdate + version: 1 + - id: refresh + version: 1 + categories: + - name: Switch + - id: switch2 + label: "照明" + capabilities: + - id: switch + version: 1 + categories: + - name: Switch + - id: switch3 + label: "强暖" + capabilities: + - id: switch + version: 1 + categories: + - name: Switch + - id: switch4 + label: "弱暖" + capabilities: + - id: switch + version: 1 + categories: + - name: Switch + - id: switch5 + label: "换气" + capabilities: + - id: switch + version: 1 + categories: + - name: Switch + - id: switch6 + label: "自然风" + capabilities: + - id: switch + version: 1 + categories: + - name: Switch + - id: switch7 + label: "干燥" + capabilities: + - id: switch + version: 1 + categories: + - name: Switch + - id: switch8 + label: "摆页" + capabilities: + - id: switch + version: 1 + categories: + - name: Switch diff --git a/drivers/SmartThings/zigbee-switch/src/init.lua b/drivers/SmartThings/zigbee-switch/src/init.lua index bd31c191bd..9e5b09139e 100644 --- a/drivers/SmartThings/zigbee-switch/src/init.lua +++ b/drivers/SmartThings/zigbee-switch/src/init.lua @@ -117,7 +117,8 @@ local zigbee_switch_driver_template = { lazy_load_if_possible("ge-link-bulb"), lazy_load_if_possible("bad_on_off_data_type"), lazy_load_if_possible("robb"), - lazy_load_if_possible("wallhero") + lazy_load_if_possible("wallhero"), + lazy_load_if_possible("laisiao") }, lifecycle_handlers = { init = device_init, diff --git a/drivers/SmartThings/zigbee-switch/src/laisiao/init.lua b/drivers/SmartThings/zigbee-switch/src/laisiao/init.lua new file mode 100755 index 0000000000..6756979f19 --- /dev/null +++ b/drivers/SmartThings/zigbee-switch/src/laisiao/init.lua @@ -0,0 +1,83 @@ +-- Copyright 2024 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 capabilities = require "st.capabilities" +local zcl_clusters = require "st.zigbee.zcl.clusters" +local socket = require "cosock.socket" + +local FINGERPRINTS = { + { mfr = "LAISIAO", model = "yuba" }, +} + +local function can_handle_laisiao(opts, driver, device, ...) + for _, fingerprint in ipairs(FINGERPRINTS) do + if device:get_manufacturer() == fingerprint.mfr and device:get_model() == fingerprint.model then + local subdriver = require("laisiao") + return true, subdriver + end + end + return false +end + +local function component_to_endpoint(device, component_id) + if component_id == "main" then + return device.fingerprinted_endpoint_id + else + local ep_num = component_id:match("switch(%d)") + return ep_num and tonumber(ep_num) or device.fingerprinted_endpoint_id + end +end + +local function endpoint_to_component(device, ep) + if ep == device.fingerprinted_endpoint_id then + return "main" + else + return string.format("switch%d", ep) + end +end + +local device_init = function(self, device) + device:set_component_to_endpoint_fn(component_to_endpoint) + device:set_endpoint_to_component_fn(endpoint_to_component) +end + +local function on_handler(driver, device, command) + local attr = capabilities.switch.switch + if command.component == "main" then + -- The main component is set to on by the device and cannot be set to on itself. It can only trigger off + device:emit_event_for_endpoint(device.fingerprinted_endpoint_id, attr.on()) + socket.sleep(1) + device:emit_event_for_endpoint(device.fingerprinted_endpoint_id, attr.off()) + else + device:send_to_component(command.component, zcl_clusters.OnOff.server.commands.On(device)) + end +end + +local laisiao_bath_heater = { + NAME = "Zigbee Laisiao Bathroom Heater", + supported_capabilities = { + capabilities.switch, + }, + lifecycle_handlers = { + init = device_init, + }, + capability_handlers = { + [capabilities.switch.ID] = { + [capabilities.switch.commands.on.NAME] = on_handler + } + }, + can_handle = can_handle_laisiao +} + +return laisiao_bath_heater diff --git a/tools/localizations/cn.csv b/tools/localizations/cn.csv index 87378d7013..24de809d71 100644 --- a/tools/localizations/cn.csv +++ b/tools/localizations/cn.csv @@ -79,3 +79,4 @@ Aqara Wireless Mini Switch T1,Aqara 无线开关 T1 "WallHero Switch (8 Way)",八位智能开关/场景面板 "WallHero Outlet",智能墙面五孔插座 "WallHero Remote Control (4-Inch)",语音场景(4寸)面板 +"Laisiao Bathroom Heater",Laisiao智能浴霸