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

Add discovery for Tube's Zigbee coordinators to ZHA #48420

Merged

Conversation

dmulcahey
Copy link
Contributor

Proposed change

This PR adds discovery for Tube zigbee gateways to ZHA.
https://www.tubeszb.com/shop/coordinators/2

Type of change

  • Dependency upgrade
  • Bugfix (non-breaking change which fixes an issue)
  • New integration (thank you!)
  • New feature (which adds functionality to an existing integration)
  • Breaking change (fix/feature causing existing functionality to break)
  • Code quality improvements to existing code or addition of tests

Example entry for configuration.yaml:

# Example configuration.yaml

Additional information

  • This PR fixes or closes issue: fixes #
  • This PR is related to issue:
  • Link to documentation pull request:

Checklist

  • The code change is tested and works locally.
  • Local tests pass. Your PR cannot be merged unless tests pass
  • There is no commented out code in this PR.
  • I have followed the development checklist
  • The code has been formatted using Black (black --fast homeassistant tests)
  • Tests have been added to verify that the new code works.

If user exposed functionality or configuration variables are added/changed:

If the code communicates with devices, web services, or third-party tools:

  • The manifest file has all fields filled out correctly.
    Updated and included derived files by running: python3 -m script.hassfest.
  • New or updated dependencies have been added to requirements_all.txt.
    Updated by running python3 -m script.gen_requirements_all.
  • Untested files have been added to .coveragerc.

The integration reached or maintains the following Integration Quality Scale:

  • No score or internal
  • 🥈 Silver
  • 🥇 Gold
  • 🏆 Platinum

To help with the load of incoming pull requests:

@probot-home-assistant
Copy link

Hey there @Adminiuga, mind taking a look at this pull request as its been labeled with an integration (zha) you are listed as a codeowner for? Thanks!
(message by CodeOwnersMention)

@Adminiuga
Copy link
Contributor

Uh-oh coverage is complain ing. Let me know when it is not draft, but so far looks good

@tube0013
Copy link
Contributor

Tested:

https://imgur.com/a/RsCCqTj

@dmulcahey dmulcahey marked this pull request as ready for review March 28, 2021 21:31
@bdraco bdraco self-requested a review March 29, 2021 00:16
@bdraco
Copy link
Member

bdraco commented Mar 29, 2021

Its working but I'm not seeing a flow title

Screen Shot 2021-03-28 at 2 35 18 PM

python3 -m script.translations develop needed?

@tube0013
Copy link
Contributor

Its working but I'm not seeing a flow title

Screen Shot 2021-03-28 at 2 35 18 PM

python3 -m script.translations develop needed?

above my head, but I manually edited en.json to get it to show for myself.

@bdraco
Copy link
Member

bdraco commented Mar 29, 2021

Testing: I actually get an exception while trying to setup.

Screen Shot 2021-03-28 at 2 39 12 PM

2021-03-29 00:39:17 DEBUG (MainThread) [zigpy_znp.zigbee.application] Failed to probe ZNP radio with config {'path': 'socket://tube_zb_gw_cc2652p2.local:6638', 'baudrate': 115200, 'flow_control': None}
Traceback (most recent call last):
  File "/usr/local/lib/python3.8/site-packages/serial/urlhandler/protocol_socket.py", line 63, in open
    self._socket = socket.create_connection(self.from_url(self.portstr), timeout=POLL_TIMEOUT)
  File "/usr/local/lib/python3.8/socket.py", line 787, in create_connection
    for res in getaddrinfo(host, port, 0, SOCK_STREAM):
  File "/usr/local/lib/python3.8/socket.py", line 918, in getaddrinfo
    for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
socket.gaierror: [Errno -2] Name does not resolve

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.8/site-packages/zigpy_znp/zigbee/application.py", line 159, in probe
    await znp.connect()
  File "/usr/local/lib/python3.8/site-packages/zigpy_znp/api.py", line 224, in connect
    self._uart = await uart.connect(self._config[conf.CONF_DEVICE], self)
  File "/usr/local/lib/python3.8/site-packages/zigpy_znp/uart.py", line 156, in connect
    transport, protocol = await serial_asyncio.create_serial_connection(
  File "/usr/local/lib/python3.8/site-packages/serial_asyncio/__init__.py", line 445, in create_serial_connection
    serial_instance = serial.serial_for_url(*args, **kwargs)
  File "/usr/local/lib/python3.8/site-packages/serial/__init__.py", line 90, in serial_for_url
    instance.open()
  File "/usr/local/lib/python3.8/site-packages/serial/urlhandler/protocol_socket.py", line 66, in open
    raise SerialException("Could not open port {}: {}".format(self.portstr, msg))
serial.serialutil.SerialException: Could not open port socket://tube_zb_gw_cc2652p2.local:6638: [Errno -2] Name does not resolve

@tube0013
Copy link
Contributor

Works here, but yea if it doesn't resolve you'll get bumped back to the dialog box. I don't know if that's such a bad thing, user could then just enter the IP address there. Goal with mdns is to not have to worry about ip changes. but if mdns is wonky for a user being able to specify the ip is good.

2021-03-28 20:47:00 DEBUG (MainThread) [zigpy_znp.zigbee.application] Probing socket://tube_zb_gw_cc2652p2.local:6638
2021-03-28 20:47:00 DEBUG (MainThread) [zigpy_znp.uart] Connecting to socket://tube_zb_gw_cc2652p2.local:6638 at 115200 baud
2021-03-28 20:47:00 DEBUG (MainThread) [zigpy_znp.uart] Opened socket://tube_zb_gw_cc2652p2.local:6638 serial port
2021-03-28 20:47:00 DEBUG (MainThread) [zigpy_znp.uart] Toggling RTS/CTS to skip CC2652R bootloader
2021-03-28 20:47:01 DEBUG (MainThread) [zigpy_znp.uart] Connected to socket://tube_zb_gw_cc2652p2.local:6638 at 115200 baud
2021-03-28 20:47:01 DEBUG (MainThread) [zigpy_znp.api] Waiting 1s before sending anything
2021-03-28 20:47:02 DEBUG (MainThread) [zigpy_znp.api] Sending bootloader skip byte
2021-03-28 20:47:02 DEBUG (MainThread) [zigpy_znp.api] Waiting 1s or until a reset indication is received
2021-03-28 20:47:03 DEBUG (MainThread) [zigpy_znp.api] Testing connection to socket://tube_zb_gw_cc2652p2.local:6638
2021-03-28 20:47:03 DEBUG (MainThread) [zigpy_znp.api] Sending request: SYS.Ping.Req()
2021-03-28 20:47:03 DEBUG (MainThread) [zigpy_znp.api] Received command: SYS.Ping.Rsp(Capabilities=<MTCapabilities.CAP_APP_CNF|CAP_GP|CAP_UTIL|CAP_ZDO|CAP_AF|CAP_SYS: 1625>)
2021-03-28 20:47:03 DEBUG (MainThread) [zigpy_znp.api] Sending request: SYS.NVLength.Req(SysId=<NvSysIds.ZSTACK: 1>, ItemId=<ExNvIds.TCLK_TABLE: 4>, SubId=0)
2021-03-28 20:47:03 DEBUG (MainThread) [zigpy_znp.api] Received command: SYS.NVLength.Rsp(Length=20)
2021-03-28 20:47:03 DEBUG (MainThread) [zigpy_znp.api] Sending request: SYS.NVRead.Req(SysId=<NvSysIds.ZSTACK: 1>, ItemId=<ExNvIds.TCLK_TABLE: 4>, SubId=0, Offset=0, Length=20)
2021-03-28 20:47:03 DEBUG (MainThread) [zigpy_znp.api] Received command: SYS.NVRead.Rsp(Status=<Status.SUCCESS: 0>, Value=b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xFF\x00\x00\x00')
2021-03-28 20:47:03 DEBUG (MainThread) [zigpy_znp.api] Detected Z-Stack 3.3
2021-03-28 20:47:03 DEBUG (MainThread) [zigpy_znp.api] Connected to socket://tube_zb_gw_cc2652p2.local:6638 at 115200 baud
2021-03-28 20:47:03 DEBUG (MainThread) [zigpy_znp.uart] Closing serial port
2021-03-28 20:47:03 INFO (MainThread) [homeassistant.setup] Setting up zha
2021-03-28 20:47:03 INFO (MainThread) [homeassistant.setup] Setup of domain zha took 0.0 seconds

@bdraco
Copy link
Member

bdraco commented Mar 29, 2021

Its likely the local name resolution works if you are running the Home Assistant Operating System but not for other options (unless its been manually configured).

aioesphomeapi has a resolver built in for this case
https://github.com/esphome/aioesphomeapi/blob/master/aioesphomeapi/host_resolver.py

...but we ended up just storing the ip & letting discovery update it in the end because it was more reliable

@dmulcahey
Copy link
Contributor Author

Its working but I'm not seeing a flow title

Screen Shot 2021-03-28 at 2 35 18 PM

python3 -m script.translations develop needed?

are you supposed to commit those? I thought the build took care of this and this was only to see the translations locally?

@bdraco
Copy link
Member

bdraco commented Mar 29, 2021

are you supposed to commit those? I thought the build took care of this and this was only to see the translations locally?

I'm not 100% sure, but I didn't one time for homekit and the integration shipped without the en.json file somehow so I've been doing it.

@Adminiuga
Copy link
Contributor

Adminiuga commented Mar 29, 2021

https://developers.home-assistant.io/docs/internationalization/core#introducing-new-strings

IIRC you add them to "strings.json" and run python3 -m script.translations develop which would update en.json and commit those

@dmulcahey
Copy link
Contributor Author

@bdraco updated. I think I took care of your points and @tube0013 tested and things are working (IP address updates automagically when it changes)

@bdraco
Copy link
Member

bdraco commented Mar 30, 2021

Will retest shortly 👍

Copy link
Member

@bdraco bdraco left a comment

Choose a reason for hiding this comment

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

Works great 👍

I originally bought this hardware for testing zha lights with HomeKit and never actually got around to setting it up. Making it discoverable was the kick in the pants I needed. Thank you!

Screen Shot 2021-03-30 at 5 05 19 AM

@dmulcahey dmulcahey merged commit 4dc885d into home-assistant:dev Mar 30, 2021
@github-actions github-actions bot locked and limited conversation to collaborators Mar 31, 2021
@dmulcahey dmulcahey deleted the dm/zha-tube-coordinator-discovery branch December 18, 2021 12:23
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants