Skip to content

Add battery reporting for Zemismart ZM85EL cover motors #2404

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: dev
Choose a base branch
from

Conversation

michalmo
Copy link

Proposed change

Zemismart ZM85EL series devices that I own report battery status as Tuya attribute 0x0D. This PR adds optional support for reporting battery level to TuyaManufacturerWindowCover and moves the 3 manufacturer ids of these devices to a new quirk, with battery support enabled.

Additional information

ZM85EL manufacturer ids are:

These devices appeared in different quirks which have the same signatures and configuration.

Checklist

  • The changes are tested and work correctly
  • pre-commit checks pass / the code has been formatted using Black
  • Tests have been added to verify that the new code works

@codecov
Copy link

codecov bot commented May 18, 2023

Codecov Report

Attention: Patch coverage is 70.00000% with 3 lines in your changes missing coverage. Please review.

Project coverage is 85.19%. Comparing base (a601847) to head (6df8092).
Report is 577 commits behind head on dev.

Files with missing lines Patch % Lines
zhaquirks/tuya/__init__.py 40.00% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##              dev    #2404      +/-   ##
==========================================
- Coverage   85.20%   85.19%   -0.02%     
==========================================
  Files         268      268              
  Lines        8444     8454      +10     
==========================================
+ Hits         7195     7202       +7     
- Misses       1249     1252       +3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@TheJulianJES TheJulianJES added Tuya Request/PR regarding a Tuya device missing tests PR has no tests and might need them labels May 18, 2023
@jezzaaa
Copy link

jezzaaa commented Sep 5, 2023

I have a "ZM25EL-08/25" which is showing up as "_TZE200_pw7mji0l".

Can someone tell me: Is the reason this PR hasn't been accepted because of the checks that weren't successful back in May? Can I do anything to make them successful?

@MattWestb
Copy link
Contributor

If looking on the tagging:
TheJulianJES added Tuya missing tests labels on May 18
and the checks you see way.

@jezzaaa
Copy link

jezzaaa commented Sep 7, 2023

Thanks @MattWestb, that helps.

It appears that codecov is complaining about just 3 of the lines added to tuya/init.py that aren't covered by any tests. I've read the ZHA Quirks doco that mentions setting up a test file for a new quirk, and that seems to but that seems to focus on the device's .py file, not the init.py file. Is there any doco/reference/example to help me understand how to add tests for the extra lines in init.py?

@MattWestb
Copy link
Contributor

I dont have the knowledge then im not one code-worrier but i think its one Q for @TheJulianJES.

@TheJulianJES
Copy link
Collaborator

Ideally, we'd get a message from the device (including battery report). In a test, we can use device.handleMessage for example and verify that the battery attribute was correctly set.

That test verifies that code (mostly) works, even when other parts (or your new code itself) is changed, without having to recheck every device.

So, can you post a message from the device (turn on debug logs) which includes battery report?

@jezzaaa
Copy link

jezzaaa commented Sep 7, 2023

Ah OK. I appreciate your guidance @TheJulianJES. I'm hoping @michalmo can provide these logs. I don't know if I can do this with how my setup is at the moment. (And just highlighting that this isn't my code, I'm just trying to see what I can do to get it past the line.)

I've enabled ZHA debug logs, but I'm not sure what I'm looking for. Is this info available in a raw Zigbee message?

I'm guessing that the quirk needs to extract the battery level as an attribute, and then it will be logged, but without @michalmo's quirk mod running on my system, this isn't going to happen. I've replicated the "zhaquirks/tuya" directory onto my system, and it loads up fine with the current release of code. But when I add @michalmo's version of init.py and ts0601_cover.py, my ZHA fails with an error:

2023-09-08 09:08:53.437 DEBUG (MainThread) [zigpy.quirks.registry] Checking quirks for _TZE200_pw7mji0l TS0601 (b0:c7:de:ff:fe:37:e0:d6)
2023-09-08 09:08:53.437 DEBUG (MainThread) [zigpy.quirks.registry] Considering <class 'tuya.ts0601_cover.TuyaZemismartSmartCover0601_3_battery'>
2023-09-08 09:08:53.437 DEBUG (MainThread) [zigpy.quirks.registry] Found custom device replacement for b0:c7:de:ff:fe:37:e0:d6: <class 'tuya.ts0601_cover.TuyaZemismartSmartCover0601_3_battery'>
2023-09-08 09:08:53.438 ERROR (MainThread) [homeassistant.config_entries] Error setting up entry ConBee II for zha
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/config_entries.py", line 387, in async_setup
    result = await component.async_setup_entry(hass, self)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/zha/__init__.py", line 142, in async_setup_entry
    await zha_gateway.async_initialize()
  File "/usr/src/homeassistant/homeassistant/components/zha/core/gateway.py", line 201, in async_initialize
    self.application_controller = await app_controller_cls.new(
                                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/zigpy/application.py", line 217, in new
    await app._load_db()
  File "/usr/local/lib/python3.11/site-packages/zigpy/application.py", line 107, in _load_db
    await self._dblistener.load()
  File "/usr/local/lib/python3.11/site-packages/zigpy/appdb.py", line 607, in load
    device = zigpy.quirks.get_device(device)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/zigpy/quirks/__init__.py", line 40, in get_device
    return _DEVICE_REGISTRY.get_device(device)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/zigpy/quirks/registry.py", line 143, in get_device
    device = candidate(device._application, device.ieee, device.nwk, device)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/zhaquirks/tuya/__init__.py", line 1335, in __init__
    super().__init__(*args, **kwargs)
  File "/usr/local/lib/python3.11/site-packages/zigpy/quirks/__init__.py", line 97, in __init__
    self.add_endpoint(endpoint_id, replace_device=replaces)
  File "/usr/local/lib/python3.11/site-packages/zigpy/quirks/__init__.py", line 114, in add_endpoint
    ep = custom_ep_type(self, endpoint_id, replacement_data, replace_device)
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/zigpy/quirks/__init__.py", line 144, in __init__
    cluster = c(self, is_server=True)
              ^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/zhaquirks/tuya/__init__.py", line 905, in __init__
    self.endpoint.device.battery_bus.add_listener(self)
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'TuyaZemismartSmartCover0601_3_battery' object has no attribute 'battery_bus'

This isn't intended to side-track this PR into a coding lesson for myself (although I could do with a few Python lessons TBH, but that's a different issue), I just wanted to show where I've stalled, in case someone else can point me in the right direction. If I can't get my own copy of the modded quirk to load, I fear that I'm not going to be much help here.

@jezzaaa
Copy link

jezzaaa commented Oct 3, 2023

I'm guessing that the quirk needs to extract the battery level as an attribute, and then it will be logged, but without @michalmo's quirk mod running on my system, this isn't going to happen. I've replicated the "zhaquirks/tuya" directory onto my system, and it loads up fine with the current release of code. But when I add @michalmo's version of init.py and ts0601_cover.py, my ZHA fails with an error:

Can anyone help me to get this modified quirk running on my system, so I can get debug logs?

@jezzaaa
Copy link

jezzaaa commented Oct 15, 2023

I'm guessing that the quirk needs to extract the battery level as an attribute, and then it will be logged, but without @michalmo's quirk mod running on my system, this isn't going to happen. I've replicated the "zhaquirks/tuya" directory onto my system, and it loads up fine with the current release of code. But when I add @michalmo's version of init.py and ts0601_cover.py, my ZHA fails with an error:

Can anyone help me to get this modified quirk running on my system, so I can get debug logs?

Nobody?

@MattWestb
Copy link
Contributor

One good start can being the wiki https://github.com/zigpy/zigpy/wiki

@TheJulianJES
Copy link
Collaborator

TheJulianJES commented Jan 19, 2024

AttributeError: 'TuyaZemismartSmartCover0601_3_battery' object has no attribute 'battery_bus'

Add something like this to the quirk where you create the battery_bus that's accessed from somewhere else:

def __init__(self, *args, **kwargs):
"""Init device."""
self.thermostat_bus = Bus()
self.ui_bus = Bus()
self.battery_bus = Bus()
super().__init__(*args, **kwargs)

The PR adds it for TuyaWindowCover and I guess you didn't modify that class when using it as a custom quirk?


The missing tests are still something that we likely need to address.

@Ryan-Scherm
Copy link

The custom quirk by stast1 in _"[Device Support Request] custom quirk for Tuya Zemismart blind cover motor TS0601 TZE200_68nvbio9 with battery #3118" brings battery level functionality to my _TZE200_pw7mji0l motors. It updates and seems to move around a bit, but it does this in the TuyaSmart app too, so I think that is something on the motor end.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
missing tests PR has no tests and might need them Tuya Request/PR regarding a Tuya device
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants