Introduce actuator base entity to microBees (#111000)
* changed library imports and added sensors to coordinator and new entity * revert library * revert library
This commit is contained in:
parent
5b470ff16f
commit
ac926f9c64
5 changed files with 25 additions and 9 deletions
|
@ -7,7 +7,9 @@ from http import HTTPStatus
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
import aiohttp
|
import aiohttp
|
||||||
from microBeesPy.microbees import Actuator, Bee, MicroBees, MicroBeesException
|
from microBeesPy.bee import Actuator, Bee
|
||||||
|
from microBeesPy.exceptions import MicroBeesException
|
||||||
|
from microBeesPy.microbees import MicroBees
|
||||||
|
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.exceptions import ConfigEntryAuthFailed
|
from homeassistant.exceptions import ConfigEntryAuthFailed
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
"""Base entity for microBees."""
|
"""Base entity for microBees."""
|
||||||
|
|
||||||
from microBeesPy.microbees import Actuator, Bee
|
from microBeesPy.bee import Actuator, Bee
|
||||||
|
|
||||||
from homeassistant.helpers.device_registry import DeviceInfo
|
from homeassistant.helpers.device_registry import DeviceInfo
|
||||||
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
||||||
|
@ -18,13 +18,10 @@ class MicroBeesEntity(CoordinatorEntity[MicroBeesUpdateCoordinator]):
|
||||||
self,
|
self,
|
||||||
coordinator: MicroBeesUpdateCoordinator,
|
coordinator: MicroBeesUpdateCoordinator,
|
||||||
bee_id: int,
|
bee_id: int,
|
||||||
actuator_id: int,
|
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Initialize the microBees entity."""
|
"""Initialize the microBees entity."""
|
||||||
super().__init__(coordinator)
|
super().__init__(coordinator)
|
||||||
self.bee_id = bee_id
|
self.bee_id = bee_id
|
||||||
self.actuator_id = actuator_id
|
|
||||||
self._attr_unique_id = f"{bee_id}_{actuator_id}"
|
|
||||||
self._attr_device_info = DeviceInfo(
|
self._attr_device_info = DeviceInfo(
|
||||||
identifiers={(DOMAIN, str(bee_id))},
|
identifiers={(DOMAIN, str(bee_id))},
|
||||||
manufacturer="microBees",
|
manufacturer="microBees",
|
||||||
|
@ -46,6 +43,21 @@ class MicroBeesEntity(CoordinatorEntity[MicroBeesUpdateCoordinator]):
|
||||||
"""Return the bee."""
|
"""Return the bee."""
|
||||||
return self.coordinator.data.bees[self.bee_id]
|
return self.coordinator.data.bees[self.bee_id]
|
||||||
|
|
||||||
|
|
||||||
|
class MicroBeesActuatorEntity(MicroBeesEntity):
|
||||||
|
"""Base class for microBees entities with actuator."""
|
||||||
|
|
||||||
|
def __init__(
|
||||||
|
self,
|
||||||
|
coordinator: MicroBeesUpdateCoordinator,
|
||||||
|
bee_id: int,
|
||||||
|
actuator_id: int,
|
||||||
|
) -> None:
|
||||||
|
"""Initialize the microBees entity."""
|
||||||
|
super().__init__(coordinator, bee_id)
|
||||||
|
self.actuator_id = actuator_id
|
||||||
|
self._attr_unique_id = f"{bee_id}_{actuator_id}"
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def actuator(self) -> Actuator:
|
def actuator(self) -> Actuator:
|
||||||
"""Return the actuator."""
|
"""Return the actuator."""
|
||||||
|
|
|
@ -9,7 +9,7 @@ from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
|
|
||||||
from .const import DOMAIN
|
from .const import DOMAIN
|
||||||
from .coordinator import MicroBeesUpdateCoordinator
|
from .coordinator import MicroBeesUpdateCoordinator
|
||||||
from .entity import MicroBeesEntity
|
from .entity import MicroBeesActuatorEntity
|
||||||
|
|
||||||
SOCKET_TRANSLATIONS = {46: "socket_it", 38: "socket_eu"}
|
SOCKET_TRANSLATIONS = {46: "socket_it", 38: "socket_eu"}
|
||||||
|
|
||||||
|
@ -28,7 +28,7 @@ async def async_setup_entry(
|
||||||
async_add_entities(switches)
|
async_add_entities(switches)
|
||||||
|
|
||||||
|
|
||||||
class MBSwitch(MicroBeesEntity, SwitchEntity):
|
class MBSwitch(MicroBeesActuatorEntity, SwitchEntity):
|
||||||
"""Representation of a microBees switch."""
|
"""Representation of a microBees switch."""
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
|
|
|
@ -2,7 +2,9 @@
|
||||||
import time
|
import time
|
||||||
from unittest.mock import AsyncMock, patch
|
from unittest.mock import AsyncMock, patch
|
||||||
|
|
||||||
from microBeesPy.microbees import Bee, MicroBees, Profile
|
from microBeesPy.bee import Bee
|
||||||
|
from microBeesPy.microbees import MicroBees
|
||||||
|
from microBeesPy.profile import Profile
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from homeassistant.components.application_credentials import (
|
from homeassistant.components.application_credentials import (
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
"""Tests for config flow."""
|
"""Tests for config flow."""
|
||||||
from unittest.mock import AsyncMock, patch
|
from unittest.mock import AsyncMock, patch
|
||||||
|
|
||||||
from microBeesPy.microbees import MicroBeesException
|
from microBeesPy.exceptions import MicroBeesException
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from homeassistant.components.microbees.const import DOMAIN
|
from homeassistant.components.microbees.const import DOMAIN
|
||||||
|
|
Loading…
Add table
Reference in a new issue