Move efergy base entity to separate module (#126051)
This commit is contained in:
parent
21b92455af
commit
9dd16d3df5
4 changed files with 33 additions and 26 deletions
|
@ -8,12 +8,7 @@ from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.const import CONF_API_KEY, Platform
|
from homeassistant.const import CONF_API_KEY, Platform
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.exceptions import ConfigEntryAuthFailed, ConfigEntryNotReady
|
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.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]
|
PLATFORMS = [Platform.SENSOR]
|
||||||
type EfergyConfigEntry = ConfigEntry[Efergy]
|
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:
|
async def async_unload_entry(hass: HomeAssistant, entry: EfergyConfigEntry) -> bool:
|
||||||
"""Unload a config entry."""
|
"""Unload a config entry."""
|
||||||
return await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
|
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"],
|
|
||||||
)
|
|
||||||
|
|
30
homeassistant/components/efergy/entity.py
Normal file
30
homeassistant/components/efergy/entity.py
Normal file
|
@ -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"],
|
||||||
|
)
|
|
@ -20,8 +20,9 @@ from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
from homeassistant.helpers.typing import StateType
|
from homeassistant.helpers.typing import StateType
|
||||||
|
|
||||||
from . import EfergyConfigEntry, EfergyEntity
|
from . import EfergyConfigEntry
|
||||||
from .const import CONF_CURRENT_VALUES, LOGGER
|
from .const import CONF_CURRENT_VALUES, LOGGER
|
||||||
|
from .entity import EfergyEntity
|
||||||
|
|
||||||
SENSOR_TYPES: tuple[SensorEntityDescription, ...] = (
|
SENSOR_TYPES: tuple[SensorEntityDescription, ...] = (
|
||||||
SensorEntityDescription(
|
SensorEntityDescription(
|
||||||
|
|
|
@ -4,7 +4,7 @@ from unittest.mock import AsyncMock, patch
|
||||||
|
|
||||||
from pyefergy import exceptions
|
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.const import CONF_API_KEY
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.setup import async_setup_component
|
from homeassistant.setup import async_setup_component
|
||||||
|
|
Loading…
Add table
Reference in a new issue