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

CHAD-14369 Add ezex valve sub-driver #1763

Merged
merged 1 commit into from
Nov 19, 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
80 changes: 80 additions & 0 deletions drivers/SmartThings/zigbee-valve/src/ezex/init.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
-- 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 clusters = require "st.zigbee.zcl.clusters"
local capabilities = require "st.capabilities"

local IASZone = clusters.IASZone
local Basic = clusters.Basic
local OnOff = clusters.OnOff

local configuration = {
{
cluster = IASZone.ID,
attribute = IASZone.attributes.ZoneStatus.ID,
minimum_interval = 0,
maximum_interval = 3600,
data_type = IASZone.attributes.ZoneStatus.base_type,
reportable_change = 1
},
{
cluster = Basic.ID,
attribute = Basic.attributes.PowerSource.ID,
minimum_interval = 30,
maximum_interval = 21600,
data_type = Basic.attributes.PowerSource.base_type,
},
{
cluster = OnOff.ID,
attribute = OnOff.attributes.OnOff.ID,
minimum_interval = 0,
maximum_interval = 600,
data_type = OnOff.attributes.OnOff.base_type
}
}

local function ias_zone_status_attr_handler(driver, device, zone_status, zb_rx)
Copy link
Contributor

@inasail inasail Nov 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't we need emit the initial battery value to cloud?
The battery level for this device are only 3 levels?(100%, 50% 5%)

Copy link
Contributor Author

@greens greens Nov 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I went into this a bit more in the Jira ticket, but very old versions of this device only ever reported their battery status using the IAS Zone Status, which can report "low battery" or "normal battery". On the DTH, for a while, we interpreted these as 5% and 50%, but the device used a custom metadata that just reported "low" and "normal".

Eventually, it seems eZex did a firmware update and started using the PowerConfiguration cluster. (and the behavior was removed from the DTH: SmartThingsCommunity/SmartThingsPublic@1fdbf08)

So only old versions (note how the can_handle function is restricted to devices that do not support the PowerConfiguration cluster) will use this handling, which will only ever report 5% or 50%, but this matches the old DTH handling of the same.

I expect that most customers in the field have the updated firmware that uses the standard Zigbee cluster for reporting battery level, so this should only ever be a corner case.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as for initial state, for these specific old devices, a read of the IAS Zone Status will occur on add or refresh that will result in a battery value of 5% or 50%.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, I got it. Thank you.

-- this is cribbed from the DTH
if zone_status:is_battery_low_set() then
device:emit_event(capabilities.battery.battery(5))
else
device:emit_event(capabilities.battery.battery(50))
end
end

local function device_init(driver, device)
for _, attribute in ipairs(configuration) do
device:add_configured_attribute(attribute)
device:add_monitored_attribute(attribute)
end
end

local ezex_valve = {
NAME = "Ezex Valve",
zigbee_handlers = {
attr = {
[IASZone.ID] = {
[IASZone.attributes.ZoneStatus.ID] = ias_zone_status_attr_handler
},
}
},
lifecycle_handlers = {
init = device_init
},
can_handle = function(opts, driver, device, ...)
return device:get_model() == "E253-KR0B0ZX-HA" and not device:supports_server_cluster(clusters.PowerConfiguration.ID)
end
}

return ezex_valve
3 changes: 2 additions & 1 deletion drivers/SmartThings/zigbee-valve/src/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ local zigbee_valve_driver_template = {
added = device_added
},
sub_drivers = {
require("sinope")
require("sinope"),
require("ezex")
}
}

Expand Down
Loading
Loading