Skip to content

Refactoring driver and support for PIR Motion Sensor #2093

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

pInksenberg
Copy link
Contributor

@pInksenberg pInksenberg commented Apr 23, 2025

Check all that apply

Type of Change

  • WWST Certification Request
    • If this is your first time contributing code:
      • I have reviewed the README.md file
      • I have reviewed the CODE_OF_CONDUCT.md file
      • I have signed the CLA
    • I plan on entering a WWST Certification Request or have entered a request through the WWST Certification console at developer.smartthings.com
  • Bug fix
  • New feature
  • Refactor

Checklist

  • I have performed a self-review of my code
  • I have commented my code in hard-to-understand areas
  • I have verified my changes by testing with a device or have communicated a plan for testing
  • I am adding new behavior, such as adding a sub-driver, and have added and run new unit tests to cover the new behavior

Description of Change

Refactoring zigbee-sensor driver.

Summary of Completed Tests

Copy link

Duplicate profile check: Passed - no duplicate profiles detected.

Copy link

github-actions bot commented Apr 23, 2025

Test Results

   66 files  +   66    426 suites  +426   0s ⏱️ ±0s
2 193 tests +2 193  2 193 ✅ +2 193  0 💤 ±0  0 ❌ ±0 
3 742 runs  +3 742  3 742 ✅ +3 742  0 💤 ±0  0 ❌ ±0 

Results for commit a59d461. ± Comparison against base commit 40b6262.

♻️ This comment has been updated with latest results.

Copy link

github-actions bot commented Apr 23, 2025

File Coverage
All files 100%

Minimum allowed coverage is 90%

Generated by 🐒 cobertura-action against a59d461

@pInksenberg pInksenberg force-pushed the generic_zigbee_sensor_improvement branch from 0f03911 to 21f22c9 Compare April 23, 2025 08:36
@pInksenberg pInksenberg force-pushed the generic_zigbee_sensor_improvement branch 5 times, most recently from 9267b81 to b81729b Compare April 24, 2025 09:44
Comment on lines 22 to 23
- 0xfe00 # EZVIZ private cluster
- 0xfe05 # EZVIZ private cluster
Copy link
Contributor

Choose a reason for hiding this comment

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

we usually capitalize the letters in our hex

Comment on lines 66 to 68
local generate_event_from_emergency = function(driver, device)
device:emit_event(capabilities.button.button.pushed({ state_change = true }))
end

local ias_ace_emergency_handler = function(driver, device)
generate_event_from_emergency(driver, device)
end
Copy link
Contributor

Choose a reason for hiding this comment

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

these functions can be consolidated

Comment on lines 26 to 47
local generate_event_from_zone_status = function(driver, device, zone_status, zb_rx)
local event
if zone_status:is_alarm1_set() or zone_status:is_alarm2_set() then
event = capabilities.contactSensor.contact.open()
else
event = capabilities.contactSensor.contact.closed()
end
if event ~= nil then
device:emit_event_for_endpoint(
zb_rx.address_header.src_endpoint.value,
event)
end
end


local ias_zone_status_attr_handler = function(driver, device, zone_status, zb_rx)
generate_event_from_zone_status(driver, device, zone_status, zb_rx)
end

local ias_zone_status_change_handler = function(driver, device, zb_rx)
generate_event_from_zone_status(driver, device, zb_rx.body.zcl_body.zone_status, zb_rx)
end
Copy link
Contributor

Choose a reason for hiding this comment

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

are we overwriting the defaults somewhere that makes it necessary to redefine them here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

you are right, we double check, and the redefine handler is not necessary and will be removed.

Copy link
Contributor

@greens greens left a comment

Choose a reason for hiding this comment

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

I'd appreciate if we could separate the zigbee generic sensor driver from the Tuya drivers.

@pInksenberg pInksenberg reopened this Apr 25, 2025
@pInksenberg
Copy link
Contributor Author

pInksenberg commented Apr 25, 2025

I'd appreciate if we could separate the zigbee generic sensor driver from the Tuya drivers.

Currently we have divided tuya and zigbee_generic_sensor into different directories, specifically located within "/drivers/generic_zigbee_sensor" and "/Unofficial/tuya" floder. Are you suggesting that we should further separate the Tuya-powered manufacturers, such as Eviz and Meian, into the "/Unofficial/tuya" folder?

@pInksenberg pInksenberg force-pushed the generic_zigbee_sensor_improvement branch 5 times, most recently from 6a5a0dd to 29fae3a Compare April 27, 2025 09:05
@greens
Copy link
Contributor

greens commented Apr 28, 2025

@pInksenberg I meant have them as two separate pull requests

@pInksenberg pInksenberg force-pushed the generic_zigbee_sensor_improvement branch from 29fae3a to 9946a16 Compare April 29, 2025 01:50
Copy link

@pInksenberg
Copy link
Contributor Author

@pInksenberg I meant have them as two separate pull requests

@greens , sure, I separated tuya devices support into another PR, please kindly check~
https://github.com/SmartThingsCommunity/SmartThingsEdgeDrivers/pull/2102/files

Comment on lines 17 to 24
- id: "generic-button-sensor"
deviceLabel: "Zigbee Generic Button"
clusters:
server:
- 0x0500
- 0xFE00 # EZVIZ private cluster
- 0xFE05 # EZVIZ private cluster
deviceProfileName: generic-remote-control
Copy link
Contributor

@greens greens Apr 29, 2025

Choose a reason for hiding this comment

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

if this device is a button it should be in the zigbee button driver

As far as I can tell it doesn't do any sensing, so it doesn't make much sense to put it here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

After our team discussions, we have no better solution for this yet. Could you please share your suggestions? How about just put it to Unofficial/ezviz directory?

Copy link
Contributor

Choose a reason for hiding this comment

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

You could do that or you could put this exact same fingerprint in the zigbee-button driver.

Copy link
Contributor

@inasail inasail May 2, 2025

Choose a reason for hiding this comment

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

@greens
Actually, this device is non-WWST device, so we can't put exact fingerprint in zigbee-button driver for this device.
As you know, zigbee-sensor have only generic fingerprint for generic purpose and scalability. I think by adding like this, we can support more ezviz button if they use same private cluster in the future(or now) for their new button devices. and If we need to support more other different types of ezviz devices in the future, then let's move this device into Unofficial/ezviz. but now, Let's just keep this device into zigbee-sensor for a while. What do you think?

  • id: "generic-button-sensor"
    deviceLabel: "Zigbee Generic Button"
    clusters:
    server:
    - 0x0500
    - 0xFE00 # EZVIZ private cluster
    - 0xFE05 # EZVIZ private cluster
    deviceProfileName: generic-remote-control

CC: @kdbang @varzac

Copy link
Contributor

Choose a reason for hiding this comment

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

put this fingerprint:

  - id: "generic-button-sensor"
    deviceLabel: "Zigbee Generic Button"
    clusters:
      server:
        - 0x0500
        - 0xFE00 # EZVIZ private cluster
        - 0xFE05 # EZVIZ private cluster
    deviceProfileName: generic-remote-control

under a new zigbeeGeneric: section here: https://github.com/SmartThingsCommunity/SmartThingsEdgeDrivers/blob/main/drivers/SmartThings/zigbee-button/fingerprints.yml

Copy link
Contributor

Choose a reason for hiding this comment

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

@greens Then, do you agree to add the generic fingerprint only for 'EZVIZ button(non-WWST)' into zigbee-button(public driver)?
I think 'Meian button' can be moved into 'Unofficial/Tuya' driver with exact fingerprint.
Actually, when we made this driver(zigbee-sensor), I misunderstood the meaning of 'sensor' as just 'iot device',
So I thought it would be okay to add the button devices into this driver(zigbee-sensor) under generic fingerprint.

Copy link
Contributor

Choose a reason for hiding this comment

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

zigbee-sensor is also a public driver. If you're adding a "generic" fingerprint for a device, that fingerprint should go in the driver that most closely matches the type of device it is. In this case it's a button.

Copy link
Contributor

Choose a reason for hiding this comment

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

@greens
Then, we will proceed as I mentioned, assuming you agree.
Meian button -> move to 'Unofficial/Tuya' with manufacturer specific fingerprint
EZVIZ button -> move to 'zigbee-button' with generic fingerprint
CC: @pInksenberg

Copy link
Contributor

Choose a reason for hiding this comment

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

what fingerprint were you expecting the Meian button to match with on this PR as-is?

Copy link
Contributor

Choose a reason for hiding this comment

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

Meian button have these clusters.
In-cluster: 0x000, 0x0001, 0x0003, 0x0500
out-cluster: 0x0501, 0x0019, 0x000A

I heard this device is matched with fingerprint below.

  • id: "generic-sensor"
    deviceLabel: "Zigbee Generic Sensor"
    clusters:
    server:
    - 0x0500
    deviceProfileName: generic-sensor

},
can_handle = is_water_sensor
}
defaults.register_for_default_handlers(generic_water_sensor, generic_water_sensor.supported_capabilities)
Copy link
Contributor

Choose a reason for hiding this comment

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

@varzac Does only registering for defaults in a specific sub-driver work like this?

Copy link
Contributor

Choose a reason for hiding this comment

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

So I think this will correctly add the zigbee and capability command handlers as it is just adding them on the "driver" table passed in and the subdrivers use the same expected structure as the base driver. However, there will be some unnecessary stuff added like cluster configurations, which I don't think are handled for subdrivers (https://github.ecodesamsung.com/iot-hub/scripting-engine/blob/main/lua_libs/st/zigbee/defaults/init.lua#L135)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Are you suggesting that using "register_for_default_handlers" in a sub-driver might cause unnecessary cluster configurations, and therefore we should implement water capability by adding specific command handlers instead of using the default approach? Could you please explain on this with more details?

Comment on lines 107 to 108
require("meian"),
require("ezviz")
Copy link
Contributor

Choose a reason for hiding this comment

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

How about changing to 'meian-button' / 'ezviz-button' for the clarity? (including the folder name of each sub drivers)

@pInksenberg pInksenberg force-pushed the generic_zigbee_sensor_improvement branch from 9946a16 to a59d461 Compare May 13, 2025 12:03
@pInksenberg
Copy link
Contributor Author

@inasail revise finished

@pInksenberg pInksenberg changed the title generic_zigbee_sensor_improvement Refactoring driver and support for PIR Motion Sensor May 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants