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

Move base entity of system_bridge to own module #103167

Merged
merged 2 commits into from
Nov 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
Expand Up @@ -1291,6 +1291,7 @@ omit =
homeassistant/components/system_bridge/__init__.py
homeassistant/components/system_bridge/binary_sensor.py
homeassistant/components/system_bridge/coordinator.py
homeassistant/components/system_bridge/entity.py
homeassistant/components/system_bridge/media_player.py
homeassistant/components/system_bridge/notify.py
homeassistant/components/system_bridge/sensor.py
Expand Down
42 changes: 0 additions & 42 deletions homeassistant/components/system_bridge/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@
discovery,
)
from homeassistant.helpers.aiohttp_client import async_get_clientsession
from homeassistant.helpers.device_registry import DeviceInfo
from homeassistant.helpers.update_coordinator import CoordinatorEntity

from .const import DOMAIN, MODULES
from .coordinator import SystemBridgeDataUpdateCoordinator
Expand Down Expand Up @@ -330,43 +328,3 @@ async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
async def async_reload_entry(hass: HomeAssistant, entry: ConfigEntry) -> None:
"""Reload the config entry when it changed."""
await hass.config_entries.async_reload(entry.entry_id)


class SystemBridgeEntity(CoordinatorEntity[SystemBridgeDataUpdateCoordinator]):
"""Defines a base System Bridge entity."""

_attr_has_entity_name = True

def __init__(
self,
coordinator: SystemBridgeDataUpdateCoordinator,
api_port: int,
key: str,
) -> None:
"""Initialize the System Bridge entity."""
super().__init__(coordinator)

self._hostname = coordinator.data.system.hostname
self._key = f"{self._hostname}_{key}"
self._configuration_url = (
f"http://{self._hostname}:{api_port}/app/settings.html"
)
self._mac_address = coordinator.data.system.mac_address
self._uuid = coordinator.data.system.uuid
self._version = coordinator.data.system.version

@property
def unique_id(self) -> str:
"""Return the unique ID for this entity."""
return self._key

@property
def device_info(self) -> DeviceInfo:
"""Return device information about this System Bridge instance."""
return DeviceInfo(
configuration_url=self._configuration_url,
connections={(dr.CONNECTION_NETWORK_MAC, self._mac_address)},
identifiers={(DOMAIN, self._uuid)},
name=self._hostname,
sw_version=self._version,
)
2 changes: 1 addition & 1 deletion homeassistant/components/system_bridge/binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback

from . import SystemBridgeEntity
from .const import DOMAIN
from .coordinator import SystemBridgeDataUpdateCoordinator
from .entity import SystemBridgeEntity


@dataclass
Expand Down
47 changes: 47 additions & 0 deletions homeassistant/components/system_bridge/entity.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
"""Base entity for the system bridge integration."""
from homeassistant.helpers import device_registry as dr
from homeassistant.helpers.device_registry import DeviceInfo
from homeassistant.helpers.update_coordinator import CoordinatorEntity

from .const import DOMAIN
from .coordinator import SystemBridgeDataUpdateCoordinator


class SystemBridgeEntity(CoordinatorEntity[SystemBridgeDataUpdateCoordinator]):
"""Defines a base System Bridge entity."""

_attr_has_entity_name = True

def __init__(
self,
coordinator: SystemBridgeDataUpdateCoordinator,
api_port: int,
key: str,
) -> None:
"""Initialize the System Bridge entity."""
super().__init__(coordinator)

self._hostname = coordinator.data.system.hostname
self._key = f"{self._hostname}_{key}"
self._configuration_url = (
f"http://{self._hostname}:{api_port}/app/settings.html"
)
self._mac_address = coordinator.data.system.mac_address
self._uuid = coordinator.data.system.uuid
self._version = coordinator.data.system.version

@property
def unique_id(self) -> str:
"""Return the unique ID for this entity."""
return self._key

@property
def device_info(self) -> DeviceInfo:
"""Return device information about this System Bridge instance."""
return DeviceInfo(
configuration_url=self._configuration_url,
connections={(dr.CONNECTION_NETWORK_MAC, self._mac_address)},
identifiers={(DOMAIN, self._uuid)},
name=self._hostname,
sw_version=self._version,
)
2 changes: 1 addition & 1 deletion homeassistant/components/system_bridge/media_player.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback

from . import SystemBridgeEntity
from .const import DOMAIN
from .coordinator import SystemBridgeCoordinatorData, SystemBridgeDataUpdateCoordinator
from .entity import SystemBridgeEntity

STATUS_CHANGING: Final[str] = "CHANGING"
STATUS_STOPPED: Final[str] = "STOPPED"
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/system_bridge/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@
from homeassistant.helpers.typing import UNDEFINED, StateType
from homeassistant.util.dt import utcnow

from . import SystemBridgeEntity
from .const import DOMAIN
from .coordinator import SystemBridgeCoordinatorData, SystemBridgeDataUpdateCoordinator
from .entity import SystemBridgeEntity

ATTR_AVAILABLE: Final = "available"
ATTR_FILESYSTEM: Final = "filesystem"
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/system_bridge/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback

from . import SystemBridgeEntity
from .const import DOMAIN
from .coordinator import SystemBridgeDataUpdateCoordinator
from .entity import SystemBridgeEntity


async def async_setup_entry(
Expand Down