home-assistant / core

:house_with_garden: Open source home automation that puts local control and privacy first.
https://www.home-assistant.io
Apache License 2.0
70.54k stars 29.46k forks source link

AppleTV Device Discovery - Invalid Device name causes system not to work #121945

Open AryasDad opened 1 month ago

AryasDad commented 1 month ago

The problem

Recently I went through various steps to get to the bottom of an issue with my AppleTV Integration where devices that always worked for several months just randomly stopped working. I first thought it was caused by HA updated code, but ended up finding that it was an iPad that recently showed up on my network with a Mal-formed name that caused things to shutdown.

Per the LOG snippet below, the device name was throwing the following exception:

zeroconf._exceptions.BadTypeInNameException: Ascii control character 0x00-0x1F and 0x7F illegal in 'N '

Once I renamed that device, it stopped causing the issue.

I recommend updating code to ignore the device with the faulty name and not cause the script to stop working due to the exception.

What version of Home Assistant Core has the issue?

core-2024.7.2

What was the last working version of Home Assistant Core?

No response

What type of installation are you running?

Home Assistant OS

Integration causing the issue

Apple TV

Link to integration documentation on our website

https://www.home-assistant.io/integrations/apple_tv

Diagnostics information

Logger: homeassistant.components.apple_tv.config_flow Source: components/apple_tv/config_flow.py:182 integration: Apple TV (documentation, issues) First occurred: 8:30:23 PM (7 occurrences) Last logged: 9:06:51 PM

Unexpected exception Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/components/apple_tv/config_flow.py", line 182, in async_step_user await self.async_find_device() File "/usr/src/homeassistant/homeassistant/components/apple_tv/config_flow.py", line 340, in async_find_device self.atv, self.atv_identifiers = await device_scan( ^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/components/apple_tv/config_flow.py", line 86, in device_scan scan_result = await scan(loop, timeout=3, hosts=_host_filter(), aiozc=aiozc) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/pyatv/init.py", line 92, in scan devices = (await scanner.discover(timeout)).values() ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/pyatv/core/scan.py", line 149, in discover await self.process(timeout) File "/usr/local/lib/python3.12/site-packages/pyatv/core/scan.py", line 455, in process services_by_address, name_to_model = await self._lookup_services_and_models( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/pyatv/core/scan.py", line 644, in _lookup_services_and_models infos = self._build_service_info_queries() ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/pyatv/core/scan.py", line 416, in _build_service_info_queries service_info = AsyncServiceInfo(zc_type, ptr_name) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "src/zeroconf/_services/info.py", line 183, in zeroconf._services.info.ServiceInfo.init File "/usr/local/lib/python3.12/site-packages/zeroconf/_utils/name.py", line 157, in service_type_name raise BadTypeInNameException( zeroconf._exceptions.BadTypeInNameException: Ascii control character 0x00-0x1F and 0x7F illegal in 'N '

Example YAML snippet

No response

Anything in the logs that might be useful for us?

No response

Additional information

No response

home-assistant[bot] commented 1 month ago

Hey there @postlund, mind taking a look at this issue as it has been labeled with an integration (apple_tv) you are listed as a code owner for? Thanks!

Code owner commands Code owners of `apple_tv` can trigger bot actions by commenting: - `@home-assistant close` Closes the issue. - `@home-assistant rename Awesome new title` Renames the issue. - `@home-assistant reopen` Reopen the issue. - `@home-assistant unassign apple_tv` Removes the current integration label and assignees on the issue, add the integration domain after the command. - `@home-assistant add-label needs-more-information` Add a label (needs-more-information, problem in dependency, problem in custom component) to the issue. - `@home-assistant remove-label needs-more-information` Remove a label (needs-more-information, problem in dependency, problem in custom component) on the issue.

(message by CodeOwnersMention)


apple_tv documentation apple_tv source (message by IssueLinks)

home-assistant[bot] commented 1 month ago

Hey there @bdraco, mind taking a look at this issue as it has been labeled with an integration (zeroconf) you are listed as a code owner for? Thanks!

Code owner commands Code owners of `zeroconf` can trigger bot actions by commenting: - `@home-assistant close` Closes the issue. - `@home-assistant rename Awesome new title` Renames the issue. - `@home-assistant reopen` Reopen the issue. - `@home-assistant unassign zeroconf` Removes the current integration label and assignees on the issue, add the integration domain after the command. - `@home-assistant add-label needs-more-information` Add a label (needs-more-information, problem in dependency, problem in custom component) to the issue. - `@home-assistant remove-label needs-more-information` Remove a label (needs-more-information, problem in dependency, problem in custom component) on the issue.

(message by CodeOwnersMention)


zeroconf documentation zeroconf source (message by IssueLinks)

bdraco commented 1 month ago

What was the original name?

AryasDad commented 1 month ago

It was "N ", without the quotes.

Not sure why it was detected as having 0x00-0x1F and 0x7F illegal characters, but who knows how the iPad got named. It is a person that is not very computer savvy and at times I have to fix things on her devices that I am not sure even how it was done, so not sure if she somehow managed to put some hidden character in her device name.