Files
core/homeassistant/components/squeezebox/entity.py
Phill (pssc) 52a99aea0c Squeezebox: Fix Allow server device details to merge with players with the same MAC (#133517)
* Disambiguate bewtween servers and player to stop them being merged

* ruff format

* make SqueezeLite players not a service

* ruff

* Tidy redunant code

* config url

* revert config url

* change to domain server

* use default to see how they are mereged with server device

* refactor to use defaults so where a player is part of a bigger ie server service device in the same intergration it doesnt replace its information

* ruff

* make test match the new data

* Fix merge

* Fix tests

* Fix meregd test data

* Fix all tests add new test for merged device in reg

* Remove info from device_info so its only a lookup

* manual merge of server player shared devices

* Fix format of merged entires

* fixes for testing

* Fix test with input from @peteS-UK device knowlonger exits for this test

* Fix test now device doesnt exits for tests

* Update homeassistant/components/squeezebox/media_player.py

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Fix Copilots formatting

* Apply suggestions from code review

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Erik Montnemery <erik@montnemery.com>
2025-06-30 11:41:22 +02:00

61 lines
2.1 KiB
Python

"""Base class for Squeezebox Sensor entities."""
from homeassistant.helpers.device_registry import (
CONNECTION_NETWORK_MAC,
DeviceInfo,
format_mac,
)
from homeassistant.helpers.entity import EntityDescription
from homeassistant.helpers.update_coordinator import CoordinatorEntity
from .const import DOMAIN, STATUS_QUERY_UUID
from .coordinator import (
LMSStatusDataUpdateCoordinator,
SqueezeBoxPlayerUpdateCoordinator,
)
class SqueezeboxEntity(CoordinatorEntity[SqueezeBoxPlayerUpdateCoordinator]):
"""Base entity class for Squeezebox entities."""
_attr_has_entity_name = True
def __init__(self, coordinator: SqueezeBoxPlayerUpdateCoordinator) -> None:
"""Initialize the SqueezeBox entity."""
super().__init__(coordinator)
self._player = coordinator.player
self._attr_device_info = DeviceInfo(
identifiers={(DOMAIN, format_mac(self._player.player_id))},
connections={(CONNECTION_NETWORK_MAC, format_mac(self._player.player_id))},
)
@property
def available(self) -> bool:
"""Return True if entity is available."""
# super().available refers to CoordinatorEntity.available (self.coordinator.last_update_success)
# self.coordinator.available is the custom availability flag from SqueezeBoxPlayerUpdateCoordinator
return self.coordinator.available and super().available
class LMSStatusEntity(CoordinatorEntity[LMSStatusDataUpdateCoordinator]):
"""Defines a base status sensor entity."""
_attr_has_entity_name = True
def __init__(
self,
coordinator: LMSStatusDataUpdateCoordinator,
description: EntityDescription,
) -> None:
"""Initialize status sensor entity."""
super().__init__(coordinator)
self.entity_description = description
self._attr_translation_key = description.key.replace(" ", "_")
self._attr_unique_id = (
f"{coordinator.data[STATUS_QUERY_UUID]}_{description.key}"
)
self._attr_device_info = DeviceInfo(
identifiers={(DOMAIN, coordinator.data[STATUS_QUERY_UUID])},
)