Apple TV Integration - tvOS 15 Beta

@postlund

I have now double checked again and can’t find any old things in my setup.

This is my latest error when I get the message “Avbruten”


Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 151, in async_init
    flow, result = await task
  File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 177, in _async_init
    result = await self._async_handle_step(flow, flow.init_step, data, init_done)
  File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 256, in _async_handle_step
    result: FlowResult = await getattr(flow, method)(user_input)
  File "/config/custom_components/apple_tv/config_flow.py", line 165, in async_step_zeroconf
    return await self.async_find_device_wrapper(self.async_found_zeroconf_device)
  File "/config/custom_components/apple_tv/config_flow.py", line 225, in async_find_device_wrapper
    return await next_func()
  File "/config/custom_components/apple_tv/config_flow.py", line 203, in async_found_zeroconf_device
    await self.async_set_unique_id(self.device_identifier)
  File "/config/custom_components/apple_tv/config_flow.py", line 105, in device_identifier
    if identifier in entry.data[CONF_IDENTIFIERS]:
KeyError: 'identifiers'

Apparently setting minimum required version is repository wide and not possible to specify per version, so locking down didn’t work. I have removed the required version, hopefully HACS will pick that up. Otherwise I will have to make another release again.

That particular error can only happen when an old entry exists. I’ll see if I can fix the migration path to at least solve that. It’s a bit tricky now as latest version only works on an unreleased version of Home Assistant, but I’ll see what I can do.

If you are using TTS with this integration (e.g. to HomePod), please see this issue or you might lose support for it: Are you using the Home Assistant integration for TTS? Look at this! · Issue #1435 · postlund/pyatv · GitHub

Hi!

Ok, the the entity be named something else’s than what for example the media_player.xxx name was? I have searched for “”apple” in my lists and can’t find anything related to this. Only phones left now

I deleted both Apple TVs from Integrations, waited for them to be discovered and added them again. Both have been working perfectly since then. Thanks for your work on this!

1 Like

When I attempt to use TTS over any Apple TV or HomePod, I receive a message stating tts cloud_say undefined.

What makes this stranger is that as soon as I see this message, Home Assistant crashes and I am forced to restart HA from my VM and I cannot find a log containing the error message. Any ideas?

I think I made the mistake of installing the most recent version without realizing that I needed an unreleased version of HA. I’ve tried removing it and reinstalling v1.6.0, but I’m still seeing the errors that others mentioned above. Is there something special I need to do to fully remove the incompatible version of the integration?

I have removed the requirement for any particular version at all and made a new release without the requirement as well, but HACS seems tot have cached the required version from before :confused: Not sure what to do about it.

Do you have any other media player that TTS works with? I believe cloud_say refers to the Nabu casa TTS service, I guess you can search the forums here in case someone else has seen the same error.

Yes. Cloud_say works perfectly with my Sonos.

Does not work at all with HomePod.

same problems like the others. In addition to that, it seems I can’t remove the devices and delete the integration. Stuck.

I have an advanced bug that may not be on the critical path, but wanted to post here if helpful. May not even be a bug, but rather a design consideration.

I have a “Skip Forward 10 seconds” button. To enable it, I pull the media_position attribute from my AppleTV and use a function in Node Red to add 10 and reset the seek position.

Home Assistant appears to cache the attributes for a period of time. That means that the current media_position attribute is often stale. Is there a trigger I can call to force the entity to refresh and get the latest attributes?

i am having the exact same problem.

git issue her https://github.com/postlund/pyatv/issues/1221

Did the non-beta get updated with the latest HA release today? Mine still isn’t working. I only updated my atv last week and avoided the beta because I assumed HA update would have the fix.

Hi @postlund. Hoping to either post a new bug, or any insights into what I’m doing wrong.

My HA environment:

  • HASSIO 2021.10.7
  • Apple TV Beta v1.6.0
  • Debug logging enabled for pyatv and custom_components.apple_tv

My Apple TV:

  • tvOS 15.1.1

When I attempt to add the Apple TV integration (Configuration → Add Integration – Apple TV) I see two different behaviors:

Behavior 1:
After clicking “Add Integration”, the pop-up screen will stall on “Please wait while the integration is being set up”. What shows in logs at this point:

2021-11-02 21:22:21 ERROR (MainThread) [homeassistant.config_entries] Error occurred loading configuration flow for integration apple_tv: cannot import name 'ATTR_CONNECTIONS' from 'homeassistant.const' (/usr/src/homeassistant/homeassistant/const.py)
2021-11-02 21:22:21 ERROR (MainThread) [homeassistant] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/config_entries.py", line 709, in async_create_flow
    integration.get_platform("config_flow")
  File "/usr/src/homeassistant/homeassistant/loader.py", line 532, in get_platform
    cache[full_name] = self._import_platform(platform_name)
  File "/usr/src/homeassistant/homeassistant/loader.py", line 537, in _import_platform
    return importlib.import_module(f"{self.pkg_path}.{platform_name}")
  File "/usr/local/lib/python3.9/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
  File "<frozen importlib._bootstrap>", line 972, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
  File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
  File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 850, in exec_module
  File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
  File "/config/custom_components/apple_tv/__init__.py", line 12, in <module>
    from homeassistant.const import (
ImportError: cannot import name 'ATTR_CONNECTIONS' from 'homeassistant.const' (/usr/src/homeassistant/homeassistant/const.py)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 151, in async_init
    flow, result = await task
  File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 169, in _async_init
    flow = await self.async_create_flow(handler, context=context, data=data)
  File "/usr/src/homeassistant/homeassistant/config_entries.py", line 716, in async_create_flow
    raise data_entry_flow.UnknownHandler
homeassistant.data_entry_flow.UnknownHandler

Behavior 2:
After clicking “Add Integration” → Search for and click “Apple TV”, pop up screen shows “Config flow could not be loaded”. From the logs, one error which also was part of the first behavior:

2021-11-02 21:26:19 ERROR (MainThread) [homeassistant.config_entries] Error occurred loading configuration flow for integration apple_tv: cannot import name 'ATTR_CONNECTIONS' from 'homeassistant.const' (/usr/src/homeassistant/homeassistant/const.py)

Appreciate any thoughts on what might be happening. Thanks.

It’s the same root cause and issue has been reported before (see cannot import name 'ATTR_CONNECTIONS' from 'homeassistant.const' · Issue #1431 · postlund/pyatv · GitHub for details). Will be resolved once Home Assistant 2021.11.0 is released today.

1 Like

The integration has retained a connection to my Apple TV 4K second generation, but the connection to the first generation Apple TV gets dropped until HA is restarted. Both Apple TVs have reserved IP addresses. Let me know if I can provide anything to help troubleshoot.

@postlund

Hi just updated to latest Apple TV Beta and also to latest Home Assistant.

When trying to pair my apple tv 3 i get stuck at this:

Pairing is required for the DMAP service. Please enter PIN XXXX on your device to continue.

No screen is showing up on my apple tv and if i just press continue i get “Avbruten”

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 197, in async_init
    flow, result = await task
  File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 224, in _async_init
    result = await self._async_handle_step(flow, flow.init_step, data, init_done)
  File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 320, in _async_handle_step
    result: FlowResult = await getattr(flow, method)(user_input)
  File "/config/custom_components/apple_tv/config_flow.py", line 165, in async_step_zeroconf
    return await self.async_find_device_wrapper(self.async_found_zeroconf_device)
  File "/config/custom_components/apple_tv/config_flow.py", line 225, in async_find_device_wrapper
    return await next_func()
  File "/config/custom_components/apple_tv/config_flow.py", line 203, in async_found_zeroconf_device
    await self.async_set_unique_id(self.device_identifier)
  File "/config/custom_components/apple_tv/config_flow.py", line 105, in device_identifier
    if identifier in entry.data[CONF_IDENTIFIERS]:
KeyError: 'identifiers'
2021-11-03 19:46:49 ERROR (MainThread) [homeassistant] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 197, in async_init
    flow, result = await task
  File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 224, in _async_init
    result = await self._async_handle_step(flow, flow.init_step, data, init_done)
  File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 320, in _async_handle_step
    result: FlowResult = await getattr(flow, method)(user_input)
  File "/config/custom_components/apple_tv/config_flow.py", line 165, in async_step_zeroconf
    return await self.async_find_device_wrapper(self.async_found_zeroconf_device)
  File "/config/custom_components/apple_tv/config_flow.py", line 225, in async_find_device_wrapper
    return await next_func()
  File "/config/custom_components/apple_tv/config_flow.py", line 203, in async_found_zeroconf_device
    await self.async_set_unique_id(self.device_identifier)
  File "/config/custom_components/apple_tv/config_flow.py", line 105, in device_identifier
    if identifier in entry.data[CONF_IDENTIFIERS]:
KeyError: 'identifiers'

Just noticed that my Apple TV 4 aborts right away after putting in the IP and click next after get prompter that I will need to fill in codes

Br Mathias

For the DMAP protocol leave it at that step in adding the integration, then you have to go on the AppleTV under settings > remotes (I don’t remember exactly the name) and find the entry called Home Assistant under the pair remotes section. That’s where you enter the code.