From 9dd16d3df5ea1e97f1c082d1c6de0e3239576246 Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Mon, 16 Sep 2024 15:21:30 +0200 Subject: [PATCH] Move efergy base entity to separate module (#126051) --- homeassistant/components/efergy/__init__.py | 24 ----------------- homeassistant/components/efergy/entity.py | 30 +++++++++++++++++++++ homeassistant/components/efergy/sensor.py | 3 ++- tests/components/efergy/__init__.py | 2 +- 4 files changed, 33 insertions(+), 26 deletions(-) create mode 100644 homeassistant/components/efergy/entity.py diff --git a/homeassistant/components/efergy/__init__.py b/homeassistant/components/efergy/__init__.py index 52979e50552..fd5aa930027 100644 --- a/homeassistant/components/efergy/__init__.py +++ b/homeassistant/components/efergy/__init__.py @@ -8,12 +8,7 @@ from homeassistant.config_entries import ConfigEntry from homeassistant.const import CONF_API_KEY, Platform from homeassistant.core import HomeAssistant from homeassistant.exceptions import ConfigEntryAuthFailed, ConfigEntryNotReady -from homeassistant.helpers import device_registry as dr from homeassistant.helpers.aiohttp_client import async_get_clientsession -from homeassistant.helpers.device_registry import DeviceInfo -from homeassistant.helpers.entity import Entity - -from .const import DEFAULT_NAME, DOMAIN PLATFORMS = [Platform.SENSOR] type EfergyConfigEntry = ConfigEntry[Efergy] @@ -47,22 +42,3 @@ async def async_setup_entry(hass: HomeAssistant, entry: EfergyConfigEntry) -> bo async def async_unload_entry(hass: HomeAssistant, entry: EfergyConfigEntry) -> bool: """Unload a config entry.""" return await hass.config_entries.async_unload_platforms(entry, PLATFORMS) - - -class EfergyEntity(Entity): - """Representation of a Efergy entity.""" - - _attr_attribution = "Data provided by Efergy" - - def __init__(self, api: Efergy, server_unique_id: str) -> None: - """Initialize an Efergy entity.""" - self.api = api - self._attr_device_info = DeviceInfo( - configuration_url="https://engage.efergy.com/user/login", - connections={(dr.CONNECTION_NETWORK_MAC, api.info["mac"])}, - identifiers={(DOMAIN, server_unique_id)}, - manufacturer=DEFAULT_NAME, - name=DEFAULT_NAME, - model=api.info["type"], - sw_version=api.info["version"], - ) diff --git a/homeassistant/components/efergy/entity.py b/homeassistant/components/efergy/entity.py new file mode 100644 index 00000000000..4cbe44d1c10 --- /dev/null +++ b/homeassistant/components/efergy/entity.py @@ -0,0 +1,30 @@ +"""The Efergy integration.""" + +from __future__ import annotations + +from pyefergy import Efergy + +from homeassistant.helpers import device_registry as dr +from homeassistant.helpers.device_registry import DeviceInfo +from homeassistant.helpers.entity import Entity + +from .const import DEFAULT_NAME, DOMAIN + + +class EfergyEntity(Entity): + """Representation of a Efergy entity.""" + + _attr_attribution = "Data provided by Efergy" + + def __init__(self, api: Efergy, server_unique_id: str) -> None: + """Initialize an Efergy entity.""" + self.api = api + self._attr_device_info = DeviceInfo( + configuration_url="https://engage.efergy.com/user/login", + connections={(dr.CONNECTION_NETWORK_MAC, api.info["mac"])}, + identifiers={(DOMAIN, server_unique_id)}, + manufacturer=DEFAULT_NAME, + name=DEFAULT_NAME, + model=api.info["type"], + sw_version=api.info["version"], + ) diff --git a/homeassistant/components/efergy/sensor.py b/homeassistant/components/efergy/sensor.py index 05c731370eb..419c4da591d 100644 --- a/homeassistant/components/efergy/sensor.py +++ b/homeassistant/components/efergy/sensor.py @@ -20,8 +20,9 @@ from homeassistant.core import HomeAssistant from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.typing import StateType -from . import EfergyConfigEntry, EfergyEntity +from . import EfergyConfigEntry from .const import CONF_CURRENT_VALUES, LOGGER +from .entity import EfergyEntity SENSOR_TYPES: tuple[SensorEntityDescription, ...] = ( SensorEntityDescription( diff --git a/tests/components/efergy/__init__.py b/tests/components/efergy/__init__.py index d763aaa2fb6..36efa77cf45 100644 --- a/tests/components/efergy/__init__.py +++ b/tests/components/efergy/__init__.py @@ -4,7 +4,7 @@ from unittest.mock import AsyncMock, patch from pyefergy import exceptions -from homeassistant.components.efergy import DOMAIN +from homeassistant.components.efergy.const import DOMAIN from homeassistant.const import CONF_API_KEY from homeassistant.core import HomeAssistant from homeassistant.setup import async_setup_component