mirror of
https://github.com/home-assistant/core.git
synced 2025-07-28 15:47:12 +00:00
Move blebox base entity to separate module (#126027)
This commit is contained in:
parent
f395688c2d
commit
9f1cc638c9
@ -4,7 +4,6 @@ import logging
|
|||||||
|
|
||||||
from blebox_uniapi.box import Box
|
from blebox_uniapi.box import Box
|
||||||
from blebox_uniapi.error import Error
|
from blebox_uniapi.error import Error
|
||||||
from blebox_uniapi.feature import Feature
|
|
||||||
from blebox_uniapi.session import ApiHost
|
from blebox_uniapi.session import ApiHost
|
||||||
|
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
@ -17,8 +16,6 @@ from homeassistant.const import (
|
|||||||
)
|
)
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.exceptions import ConfigEntryNotReady
|
from homeassistant.exceptions import ConfigEntryNotReady
|
||||||
from homeassistant.helpers.device_registry import DeviceInfo
|
|
||||||
from homeassistant.helpers.entity import Entity
|
|
||||||
|
|
||||||
from .const import DEFAULT_SETUP_TIMEOUT, DOMAIN, PRODUCT
|
from .const import DEFAULT_SETUP_TIMEOUT, DOMAIN, PRODUCT
|
||||||
from .helpers import get_maybe_authenticated_session
|
from .helpers import get_maybe_authenticated_session
|
||||||
@ -75,29 +72,3 @@ async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|||||||
hass.data[DOMAIN].pop(entry.entry_id)
|
hass.data[DOMAIN].pop(entry.entry_id)
|
||||||
|
|
||||||
return unload_ok
|
return unload_ok
|
||||||
|
|
||||||
|
|
||||||
class BleBoxEntity[_FeatureT: Feature](Entity):
|
|
||||||
"""Implements a common class for entities representing a BleBox feature."""
|
|
||||||
|
|
||||||
def __init__(self, feature: _FeatureT) -> None:
|
|
||||||
"""Initialize a BleBox entity."""
|
|
||||||
self._feature = feature
|
|
||||||
self._attr_name = feature.full_name
|
|
||||||
self._attr_unique_id = feature.unique_id
|
|
||||||
product = feature.product
|
|
||||||
self._attr_device_info = DeviceInfo(
|
|
||||||
identifiers={(DOMAIN, product.unique_id)},
|
|
||||||
manufacturer=product.brand,
|
|
||||||
model=product.model,
|
|
||||||
name=product.name,
|
|
||||||
sw_version=product.firmware_version,
|
|
||||||
configuration_url=f"http://{product.address}",
|
|
||||||
)
|
|
||||||
|
|
||||||
async def async_update(self) -> None:
|
|
||||||
"""Update the entity state."""
|
|
||||||
try:
|
|
||||||
await self._feature.async_update()
|
|
||||||
except Error as ex:
|
|
||||||
_LOGGER.error("Updating '%s' failed: %s", self.name, ex)
|
|
||||||
|
@ -12,7 +12,8 @@ from homeassistant.config_entries import ConfigEntry
|
|||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
|
|
||||||
from . import DOMAIN, PRODUCT, BleBoxEntity
|
from .const import DOMAIN, PRODUCT
|
||||||
|
from .entity import BleBoxEntity
|
||||||
|
|
||||||
BINARY_SENSOR_TYPES = (
|
BINARY_SENSOR_TYPES = (
|
||||||
BinarySensorEntityDescription(
|
BinarySensorEntityDescription(
|
||||||
|
@ -10,8 +10,8 @@ from homeassistant.config_entries import ConfigEntry
|
|||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
|
|
||||||
from . import BleBoxEntity
|
|
||||||
from .const import DOMAIN, PRODUCT
|
from .const import DOMAIN, PRODUCT
|
||||||
|
from .entity import BleBoxEntity
|
||||||
|
|
||||||
|
|
||||||
async def async_setup_entry(
|
async def async_setup_entry(
|
||||||
|
@ -17,8 +17,8 @@ from homeassistant.const import ATTR_TEMPERATURE, UnitOfTemperature
|
|||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
|
|
||||||
from . import BleBoxEntity
|
|
||||||
from .const import DOMAIN, PRODUCT
|
from .const import DOMAIN, PRODUCT
|
||||||
|
from .entity import BleBoxEntity
|
||||||
|
|
||||||
SCAN_INTERVAL = timedelta(seconds=5)
|
SCAN_INTERVAL = timedelta(seconds=5)
|
||||||
|
|
||||||
|
@ -20,8 +20,8 @@ from homeassistant.const import STATE_CLOSED, STATE_CLOSING, STATE_OPEN, STATE_O
|
|||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
|
|
||||||
from . import BleBoxEntity
|
|
||||||
from .const import DOMAIN, PRODUCT
|
from .const import DOMAIN, PRODUCT
|
||||||
|
from .entity import BleBoxEntity
|
||||||
|
|
||||||
BLEBOX_TO_COVER_DEVICE_CLASSES = {
|
BLEBOX_TO_COVER_DEVICE_CLASSES = {
|
||||||
"gate": CoverDeviceClass.GATE,
|
"gate": CoverDeviceClass.GATE,
|
||||||
|
39
homeassistant/components/blebox/entity.py
Normal file
39
homeassistant/components/blebox/entity.py
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
"""Base entity for the BleBox devices integration."""
|
||||||
|
|
||||||
|
import logging
|
||||||
|
|
||||||
|
from blebox_uniapi.error import Error
|
||||||
|
from blebox_uniapi.feature import Feature
|
||||||
|
|
||||||
|
from homeassistant.helpers.device_registry import DeviceInfo
|
||||||
|
from homeassistant.helpers.entity import Entity
|
||||||
|
|
||||||
|
from .const import DOMAIN
|
||||||
|
|
||||||
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
class BleBoxEntity[_FeatureT: Feature](Entity):
|
||||||
|
"""Implements a common class for entities representing a BleBox feature."""
|
||||||
|
|
||||||
|
def __init__(self, feature: _FeatureT) -> None:
|
||||||
|
"""Initialize a BleBox entity."""
|
||||||
|
self._feature = feature
|
||||||
|
self._attr_name = feature.full_name
|
||||||
|
self._attr_unique_id = feature.unique_id
|
||||||
|
product = feature.product
|
||||||
|
self._attr_device_info = DeviceInfo(
|
||||||
|
identifiers={(DOMAIN, product.unique_id)},
|
||||||
|
manufacturer=product.brand,
|
||||||
|
model=product.model,
|
||||||
|
name=product.name,
|
||||||
|
sw_version=product.firmware_version,
|
||||||
|
configuration_url=f"http://{product.address}",
|
||||||
|
)
|
||||||
|
|
||||||
|
async def async_update(self) -> None:
|
||||||
|
"""Update the entity state."""
|
||||||
|
try:
|
||||||
|
await self._feature.async_update()
|
||||||
|
except Error as ex:
|
||||||
|
_LOGGER.error("Updating '%s' failed: %s", self.name, ex)
|
@ -25,8 +25,8 @@ from homeassistant.config_entries import ConfigEntry
|
|||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
|
|
||||||
from . import BleBoxEntity
|
|
||||||
from .const import DOMAIN, PRODUCT
|
from .const import DOMAIN, PRODUCT
|
||||||
|
from .entity import BleBoxEntity
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
@ -27,8 +27,8 @@ from homeassistant.const import (
|
|||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
|
|
||||||
from . import BleBoxEntity
|
|
||||||
from .const import DOMAIN, PRODUCT
|
from .const import DOMAIN, PRODUCT
|
||||||
|
from .entity import BleBoxEntity
|
||||||
|
|
||||||
SENSOR_TYPES = (
|
SENSOR_TYPES = (
|
||||||
SensorEntityDescription(
|
SensorEntityDescription(
|
||||||
|
@ -11,8 +11,8 @@ from homeassistant.config_entries import ConfigEntry
|
|||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
|
|
||||||
from . import BleBoxEntity
|
|
||||||
from .const import DOMAIN, PRODUCT
|
from .const import DOMAIN, PRODUCT
|
||||||
|
from .entity import BleBoxEntity
|
||||||
|
|
||||||
SCAN_INTERVAL = timedelta(seconds=5)
|
SCAN_INTERVAL = timedelta(seconds=5)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user