fix(media_player): F1 — extra_state_attributes must be a property (t40 blocker)

Reported from a live install: the entity never rendered, and every state write
raised ``TypeError: 'method' object is not iterable``.

Root cause, from HA's own code (homeassistant/helpers/entity.py,
``__async_calculate_state``):

    if extra_state_attributes := self.extra_state_attributes:
        attr |= extra_state_attributes

``attr`` is a dict, so ``|=`` needs a mapping — and this was declared as a plain
method while the sensors' were properties. Reproduced against the pre-fix tree
with real HA: instantiating the entity and calling ``async_write_ha_state()``
prints ``REPRODUCED TypeError: 'method' object is not iterable``; with the fix
the same call writes the state and the extra attributes through.

The stub suites could never see it: their harness replaces
``async_write_ha_state``, so the method was simply called and returned a dict.
tests/test_ha_api_drift.py now drives HA's real state calculation for every
entity, and the drift sweep grew an entity-contract pass (next commit).
This commit is contained in:
James Mackay committed 2026-10-11 06:02:08 +01:00
1 parent c588a7c66b
commit acc7bc3d01
1 file changed
+9
@@ -825,7 +825,16 @@ class NvidiaShieldMediaPlayer(MediaPlayerEntity):
}
)
@property
def extra_state_attributes(self) -> dict:
"""Extra state attributes — a PROPERTY, as HA requires (t40 blocker).
``Entity.__async_calculate_state`` merges them with
``attr |= self.extra_state_attributes``; declaring this as a plain
method made every state write raise
``TypeError: 'method' object is not iterable``, so the entity could
never render on a live install.
"""
# Now playing: prefer Jellyfin, fall back to ADB media session,
# then the foreground tier (P3-3a).
now_playing = self._get_now_playing()