diff --git a/drivers/SmartThings/zigbee-switch/fingerprints.yml b/drivers/SmartThings/zigbee-switch/fingerprints.yml index 8765be8aeb..bd0bd06171 100644 --- a/drivers/SmartThings/zigbee-switch/fingerprints.yml +++ b/drivers/SmartThings/zigbee-switch/fingerprints.yml @@ -1100,6 +1100,11 @@ zigbeeManufacturer: manufacturer: Third Reality, Inc model: 3RSP02028BZ deviceProfileName: switch-power-energy + - id: "Third Reality/3RDP01072Z" + deviceLabel: ThirdReality Smart Dual Plug ZP1 + manufacturer: Third Reality, Inc + model: 3RDP01072Z + deviceProfileName: switch-power-energy - id: "DAWON_DNS/PM-S140-ZB" deviceLabel: Dawon Switch manufacturer: DAWON_DNS diff --git a/drivers/SmartThings/zigbee-switch/src/sub_drivers.lua b/drivers/SmartThings/zigbee-switch/src/sub_drivers.lua index 5dcf24ca74..238b03a6d7 100644 --- a/drivers/SmartThings/zigbee-switch/src/sub_drivers.lua +++ b/drivers/SmartThings/zigbee-switch/src/sub_drivers.lua @@ -35,5 +35,6 @@ return { lazy_load_if_possible("tuya-multi"), lazy_load_if_possible("frient"), lazy_load_if_possible("frient-IO"), - lazy_load_if_possible("color_temp_range_handlers") + lazy_load_if_possible("color_temp_range_handlers"), + lazy_load_if_possible("thirdreality-dual-plug") } diff --git a/drivers/SmartThings/zigbee-switch/src/thirdreality-dual-plug/init.lua b/drivers/SmartThings/zigbee-switch/src/thirdreality-dual-plug/init.lua new file mode 100644 index 0000000000..8faefc9135 --- /dev/null +++ b/drivers/SmartThings/zigbee-switch/src/thirdreality-dual-plug/init.lua @@ -0,0 +1,85 @@ +-- Copyright 2022 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 st_device = require "st.device" +local clusters = require "st.zigbee.zcl.clusters" +local OnOff = clusters.OnOff +local ElectricalMeasurement = clusters.ElectricalMeasurement +local utils = require "st.utils" + +local CHILD_ENDPOINT = 2 + +local ZIGBEE_DUAL_METERING_SWITCH_FINGERPRINT = { + {mfr = "Third Reality, Inc", model = "3RDP01072Z"} +} + +local function can_handle_zigbee_dual_metering_switch(opts, driver, device, ...) + for _, fingerprint in ipairs(ZIGBEE_DUAL_METERING_SWITCH_FINGERPRINT) do + if device:get_manufacturer() == fingerprint.mfr and device:get_model() == fingerprint.model then + local subdriver = require("thirdreality-dual-plug") + return true, subdriver + end + end + return false +end + +local function do_refresh(self, device) + device:send(OnOff.attributes.OnOff:read(device)) + device:send(ElectricalMeasurement.attributes.ActivePower:read(device)) +end + +local function find_child(parent, ep_id) + return parent:get_child_by_parent_assigned_key(string.format("%02X", ep_id)) +end + +local function device_added(driver, device, event) + if device.network_type == st_device.NETWORK_TYPE_ZIGBEE and + not (device.child_ids and utils.table_size(device.child_ids) ~= 0) and + find_child(device, CHILD_ENDPOINT) == nil then + + local name = "ThirdReality Smart Dual Plug ZP1" + local metadata = { + type = "EDGE_CHILD", + label = name, + profile = "switch-power-energy", + parent_device_id = device.id, + parent_assigned_child_key = string.format("%02X", CHILD_ENDPOINT), + vendor_provided_label = name, + } + driver:try_create_device(metadata) + end + do_refresh(driver, device) +end + +local function device_init(driver, device) + if device.network_type == st_device.NETWORK_TYPE_ZIGBEE then + device:set_find_child(find_child) + end +end + +local zigbee_dual_metering_switch = { + NAME = "ThirdReality Smart Dual Plug ZP1", + capability_handlers = { + [capabilities.refresh.ID] = { + [capabilities.refresh.commands.refresh.NAME] = do_refresh + } + }, + lifecycle_handlers = { + init = device_init, + added = device_added + }, + can_handle = can_handle_zigbee_dual_metering_switch +} + +return zigbee_dual_metering_switch