mirror of
https://github.com/home-assistant/core.git
synced 2025-07-21 20:27:08 +00:00
Small cleanups to bond entities (#121641)
This commit is contained in:
parent
e812b0e02f
commit
02b12837d4
@ -4,7 +4,7 @@ from __future__ import annotations
|
|||||||
|
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
|
|
||||||
from bond_async import Action, BPUPSubscriptions
|
from bond_async import Action
|
||||||
|
|
||||||
from homeassistant.components.button import ButtonEntity, ButtonEntityDescription
|
from homeassistant.components.button import ButtonEntity, ButtonEntityDescription
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
@ -12,7 +12,8 @@ from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
|||||||
|
|
||||||
from . import BondConfigEntry
|
from . import BondConfigEntry
|
||||||
from .entity import BondEntity
|
from .entity import BondEntity
|
||||||
from .utils import BondDevice, BondHub
|
from .models import BondData
|
||||||
|
from .utils import BondDevice
|
||||||
|
|
||||||
# The api requires a step size even though it does not
|
# The api requires a step size even though it does not
|
||||||
# seem to matter what is is as the underlying device is likely
|
# seem to matter what is is as the underlying device is likely
|
||||||
@ -246,13 +247,11 @@ async def async_setup_entry(
|
|||||||
) -> None:
|
) -> None:
|
||||||
"""Set up Bond button devices."""
|
"""Set up Bond button devices."""
|
||||||
data = entry.runtime_data
|
data = entry.runtime_data
|
||||||
hub = data.hub
|
|
||||||
bpup_subs = data.bpup_subs
|
|
||||||
entities: list[BondButtonEntity] = []
|
entities: list[BondButtonEntity] = []
|
||||||
|
|
||||||
for device in hub.devices:
|
for device in data.hub.devices:
|
||||||
device_entities = [
|
device_entities = [
|
||||||
BondButtonEntity(hub, device, bpup_subs, description)
|
BondButtonEntity(data, device, description)
|
||||||
for description in BUTTONS
|
for description in BUTTONS
|
||||||
if device.has_action(description.key)
|
if device.has_action(description.key)
|
||||||
and (
|
and (
|
||||||
@ -264,9 +263,7 @@ async def async_setup_entry(
|
|||||||
# Most devices have the stop action available, but
|
# Most devices have the stop action available, but
|
||||||
# we only add the stop action button if we add actions
|
# we only add the stop action button if we add actions
|
||||||
# since its not so useful if there are no actions to stop
|
# since its not so useful if there are no actions to stop
|
||||||
device_entities.append(
|
device_entities.append(BondButtonEntity(data, device, STOP_BUTTON))
|
||||||
BondButtonEntity(hub, device, bpup_subs, STOP_BUTTON)
|
|
||||||
)
|
|
||||||
entities.extend(device_entities)
|
entities.extend(device_entities)
|
||||||
|
|
||||||
async_add_entities(entities)
|
async_add_entities(entities)
|
||||||
@ -279,26 +276,23 @@ class BondButtonEntity(BondEntity, ButtonEntity):
|
|||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
hub: BondHub,
|
data: BondData,
|
||||||
device: BondDevice,
|
device: BondDevice,
|
||||||
bpup_subs: BPUPSubscriptions,
|
|
||||||
description: BondButtonEntityDescription,
|
description: BondButtonEntityDescription,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Init Bond button."""
|
"""Init Bond button."""
|
||||||
self.entity_description = description
|
self.entity_description = description
|
||||||
super().__init__(
|
super().__init__(data, device, description.name, description.key.lower())
|
||||||
hub, device, bpup_subs, description.name, description.key.lower()
|
|
||||||
)
|
|
||||||
|
|
||||||
async def async_press(self) -> None:
|
async def async_press(self) -> None:
|
||||||
"""Press the button."""
|
"""Press the button."""
|
||||||
if self.entity_description.argument:
|
description = self.entity_description
|
||||||
action = Action(
|
key = description.key
|
||||||
self.entity_description.key, self.entity_description.argument
|
if argument := description.argument:
|
||||||
)
|
action = Action(key, argument)
|
||||||
else:
|
else:
|
||||||
action = Action(self.entity_description.key)
|
action = Action(key)
|
||||||
await self._hub.bond.action(self._device.device_id, action)
|
await self._bond.action(self._device_id, action)
|
||||||
|
|
||||||
def _apply_state(self) -> None:
|
def _apply_state(self) -> None:
|
||||||
"""Apply the state."""
|
"""Apply the state."""
|
||||||
|
@ -4,7 +4,7 @@ from __future__ import annotations
|
|||||||
|
|
||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
from bond_async import Action, BPUPSubscriptions, DeviceType
|
from bond_async import Action, DeviceType
|
||||||
|
|
||||||
from homeassistant.components.cover import (
|
from homeassistant.components.cover import (
|
||||||
ATTR_POSITION,
|
ATTR_POSITION,
|
||||||
@ -17,7 +17,8 @@ from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
|||||||
|
|
||||||
from . import BondConfigEntry
|
from . import BondConfigEntry
|
||||||
from .entity import BondEntity
|
from .entity import BondEntity
|
||||||
from .utils import BondDevice, BondHub
|
from .models import BondData
|
||||||
|
from .utils import BondDevice
|
||||||
|
|
||||||
|
|
||||||
def _bond_to_hass_position(bond_position: int) -> int:
|
def _bond_to_hass_position(bond_position: int) -> int:
|
||||||
@ -37,12 +38,9 @@ async def async_setup_entry(
|
|||||||
) -> None:
|
) -> None:
|
||||||
"""Set up Bond cover devices."""
|
"""Set up Bond cover devices."""
|
||||||
data = entry.runtime_data
|
data = entry.runtime_data
|
||||||
hub = data.hub
|
|
||||||
bpup_subs = data.bpup_subs
|
|
||||||
|
|
||||||
async_add_entities(
|
async_add_entities(
|
||||||
BondCover(hub, device, bpup_subs)
|
BondCover(data, device)
|
||||||
for device in hub.devices
|
for device in data.hub.devices
|
||||||
if device.type == DeviceType.MOTORIZED_SHADES
|
if device.type == DeviceType.MOTORIZED_SHADES
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -52,11 +50,9 @@ class BondCover(BondEntity, CoverEntity):
|
|||||||
|
|
||||||
_attr_device_class = CoverDeviceClass.SHADE
|
_attr_device_class = CoverDeviceClass.SHADE
|
||||||
|
|
||||||
def __init__(
|
def __init__(self, data: BondData, device: BondDevice) -> None:
|
||||||
self, hub: BondHub, device: BondDevice, bpup_subs: BPUPSubscriptions
|
|
||||||
) -> None:
|
|
||||||
"""Create HA entity representing Bond cover."""
|
"""Create HA entity representing Bond cover."""
|
||||||
super().__init__(hub, device, bpup_subs)
|
super().__init__(data, device)
|
||||||
supported_features = CoverEntityFeature(0)
|
supported_features = CoverEntityFeature(0)
|
||||||
if self._device.supports_set_position():
|
if self._device.supports_set_position():
|
||||||
supported_features |= CoverEntityFeature.SET_POSITION
|
supported_features |= CoverEntityFeature.SET_POSITION
|
||||||
@ -84,31 +80,31 @@ class BondCover(BondEntity, CoverEntity):
|
|||||||
|
|
||||||
async def async_set_cover_position(self, **kwargs: Any) -> None:
|
async def async_set_cover_position(self, **kwargs: Any) -> None:
|
||||||
"""Set the cover position."""
|
"""Set the cover position."""
|
||||||
await self._hub.bond.action(
|
await self._bond.action(
|
||||||
self._device.device_id,
|
self._device_id,
|
||||||
Action.set_position(_hass_to_bond_position(kwargs[ATTR_POSITION])),
|
Action.set_position(_hass_to_bond_position(kwargs[ATTR_POSITION])),
|
||||||
)
|
)
|
||||||
|
|
||||||
async def async_open_cover(self, **kwargs: Any) -> None:
|
async def async_open_cover(self, **kwargs: Any) -> None:
|
||||||
"""Open the cover."""
|
"""Open the cover."""
|
||||||
await self._hub.bond.action(self._device.device_id, Action.open())
|
await self._bond.action(self._device_id, Action.open())
|
||||||
|
|
||||||
async def async_close_cover(self, **kwargs: Any) -> None:
|
async def async_close_cover(self, **kwargs: Any) -> None:
|
||||||
"""Close cover."""
|
"""Close cover."""
|
||||||
await self._hub.bond.action(self._device.device_id, Action.close())
|
await self._bond.action(self._device_id, Action.close())
|
||||||
|
|
||||||
async def async_stop_cover(self, **kwargs: Any) -> None:
|
async def async_stop_cover(self, **kwargs: Any) -> None:
|
||||||
"""Hold cover."""
|
"""Hold cover."""
|
||||||
await self._hub.bond.action(self._device.device_id, Action.hold())
|
await self._bond.action(self._device_id, Action.hold())
|
||||||
|
|
||||||
async def async_open_cover_tilt(self, **kwargs: Any) -> None:
|
async def async_open_cover_tilt(self, **kwargs: Any) -> None:
|
||||||
"""Open the cover tilt."""
|
"""Open the cover tilt."""
|
||||||
await self._hub.bond.action(self._device.device_id, Action.tilt_open())
|
await self._bond.action(self._device_id, Action.tilt_open())
|
||||||
|
|
||||||
async def async_close_cover_tilt(self, **kwargs: Any) -> None:
|
async def async_close_cover_tilt(self, **kwargs: Any) -> None:
|
||||||
"""Close the cover tilt."""
|
"""Close the cover tilt."""
|
||||||
await self._hub.bond.action(self._device.device_id, Action.tilt_close())
|
await self._bond.action(self._device_id, Action.tilt_close())
|
||||||
|
|
||||||
async def async_stop_cover_tilt(self, **kwargs: Any) -> None:
|
async def async_stop_cover_tilt(self, **kwargs: Any) -> None:
|
||||||
"""Stop the cover."""
|
"""Stop the cover."""
|
||||||
await self._hub.bond.action(self._device.device_id, Action.hold())
|
await self._bond.action(self._device_id, Action.hold())
|
||||||
|
@ -8,7 +8,6 @@ from datetime import datetime
|
|||||||
import logging
|
import logging
|
||||||
|
|
||||||
from aiohttp import ClientError
|
from aiohttp import ClientError
|
||||||
from bond_async import BPUPSubscriptions
|
|
||||||
|
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
ATTR_HW_VERSION,
|
ATTR_HW_VERSION,
|
||||||
@ -24,7 +23,8 @@ from homeassistant.helpers.entity import Entity
|
|||||||
from homeassistant.helpers.event import async_call_later
|
from homeassistant.helpers.event import async_call_later
|
||||||
|
|
||||||
from .const import DOMAIN
|
from .const import DOMAIN
|
||||||
from .utils import BondDevice, BondHub
|
from .models import BondData
|
||||||
|
from .utils import BondDevice
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
@ -39,19 +39,20 @@ class BondEntity(Entity):
|
|||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
hub: BondHub,
|
data: BondData,
|
||||||
device: BondDevice,
|
device: BondDevice,
|
||||||
bpup_subs: BPUPSubscriptions,
|
|
||||||
sub_device: str | None = None,
|
sub_device: str | None = None,
|
||||||
sub_device_id: str | None = None,
|
sub_device_id: str | None = None,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Initialize entity with API and device info."""
|
"""Initialize entity with API and device info."""
|
||||||
|
hub = data.hub
|
||||||
self._hub = hub
|
self._hub = hub
|
||||||
|
self._bond = hub.bond
|
||||||
self._device = device
|
self._device = device
|
||||||
self._device_id = device.device_id
|
self._device_id = device.device_id
|
||||||
self._sub_device = sub_device
|
self._sub_device = sub_device
|
||||||
self._attr_available = True
|
self._attr_available = True
|
||||||
self._bpup_subs = bpup_subs
|
self._bpup_subs = data.bpup_subs
|
||||||
self._update_lock = Lock()
|
self._update_lock = Lock()
|
||||||
self._initialized = False
|
self._initialized = False
|
||||||
if sub_device_id:
|
if sub_device_id:
|
||||||
@ -79,7 +80,7 @@ class BondEntity(Entity):
|
|||||||
device_info = DeviceInfo(
|
device_info = DeviceInfo(
|
||||||
manufacturer=self._hub.make,
|
manufacturer=self._hub.make,
|
||||||
# type ignore: tuple items should not be Optional
|
# type ignore: tuple items should not be Optional
|
||||||
identifiers={(DOMAIN, self._hub.bond_id, self._device.device_id)}, # type: ignore[arg-type]
|
identifiers={(DOMAIN, self._hub.bond_id, self._device_id)}, # type: ignore[arg-type]
|
||||||
configuration_url=f"http://{self._hub.host}",
|
configuration_url=f"http://{self._hub.host}",
|
||||||
)
|
)
|
||||||
if self.name is not None:
|
if self.name is not None:
|
||||||
@ -141,7 +142,7 @@ class BondEntity(Entity):
|
|||||||
async def _async_update_from_api(self) -> None:
|
async def _async_update_from_api(self) -> None:
|
||||||
"""Fetch via the API."""
|
"""Fetch via the API."""
|
||||||
try:
|
try:
|
||||||
state: dict = await self._hub.bond.device_state(self._device_id)
|
state: dict = await self._bond.device_state(self._device_id)
|
||||||
except (ClientError, TimeoutError, OSError) as error:
|
except (ClientError, TimeoutError, OSError) as error:
|
||||||
if self.available:
|
if self.available:
|
||||||
_LOGGER.warning(
|
_LOGGER.warning(
|
||||||
|
@ -7,7 +7,7 @@ import math
|
|||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
from aiohttp.client_exceptions import ClientResponseError
|
from aiohttp.client_exceptions import ClientResponseError
|
||||||
from bond_async import Action, BPUPSubscriptions, DeviceType, Direction
|
from bond_async import Action, DeviceType, Direction
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
from homeassistant.components.fan import (
|
from homeassistant.components.fan import (
|
||||||
@ -29,7 +29,8 @@ from homeassistant.util.scaling import int_states_in_range
|
|||||||
from . import BondConfigEntry
|
from . import BondConfigEntry
|
||||||
from .const import SERVICE_SET_FAN_SPEED_TRACKED_STATE
|
from .const import SERVICE_SET_FAN_SPEED_TRACKED_STATE
|
||||||
from .entity import BondEntity
|
from .entity import BondEntity
|
||||||
from .utils import BondDevice, BondHub
|
from .models import BondData
|
||||||
|
from .utils import BondDevice
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
@ -43,8 +44,6 @@ async def async_setup_entry(
|
|||||||
) -> None:
|
) -> None:
|
||||||
"""Set up Bond fan devices."""
|
"""Set up Bond fan devices."""
|
||||||
data = entry.runtime_data
|
data = entry.runtime_data
|
||||||
hub = data.hub
|
|
||||||
bpup_subs = data.bpup_subs
|
|
||||||
platform = entity_platform.async_get_current_platform()
|
platform = entity_platform.async_get_current_platform()
|
||||||
platform.async_register_entity_service(
|
platform.async_register_entity_service(
|
||||||
SERVICE_SET_FAN_SPEED_TRACKED_STATE,
|
SERVICE_SET_FAN_SPEED_TRACKED_STATE,
|
||||||
@ -53,8 +52,8 @@ async def async_setup_entry(
|
|||||||
)
|
)
|
||||||
|
|
||||||
async_add_entities(
|
async_add_entities(
|
||||||
BondFan(hub, device, bpup_subs)
|
BondFan(data, device)
|
||||||
for device in hub.devices
|
for device in data.hub.devices
|
||||||
if DeviceType.is_fan(device.type)
|
if DeviceType.is_fan(device.type)
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -62,14 +61,12 @@ async def async_setup_entry(
|
|||||||
class BondFan(BondEntity, FanEntity):
|
class BondFan(BondEntity, FanEntity):
|
||||||
"""Representation of a Bond fan."""
|
"""Representation of a Bond fan."""
|
||||||
|
|
||||||
def __init__(
|
def __init__(self, data: BondData, device: BondDevice) -> None:
|
||||||
self, hub: BondHub, device: BondDevice, bpup_subs: BPUPSubscriptions
|
|
||||||
) -> None:
|
|
||||||
"""Create HA entity representing Bond fan."""
|
"""Create HA entity representing Bond fan."""
|
||||||
self._power: bool | None = None
|
self._power: bool | None = None
|
||||||
self._speed: int | None = None
|
self._speed: int | None = None
|
||||||
self._direction: int | None = None
|
self._direction: int | None = None
|
||||||
super().__init__(hub, device, bpup_subs)
|
super().__init__(data, device)
|
||||||
if self._device.has_action(Action.BREEZE_ON):
|
if self._device.has_action(Action.BREEZE_ON):
|
||||||
self._attr_preset_modes = [PRESET_MODE_BREEZE]
|
self._attr_preset_modes = [PRESET_MODE_BREEZE]
|
||||||
features = FanEntityFeature(0)
|
features = FanEntityFeature(0)
|
||||||
@ -136,15 +133,13 @@ class BondFan(BondEntity, FanEntity):
|
|||||||
bond_speed,
|
bond_speed,
|
||||||
)
|
)
|
||||||
|
|
||||||
await self._hub.bond.action(
|
await self._bond.action(self._device_id, Action.set_speed(bond_speed))
|
||||||
self._device.device_id, Action.set_speed(bond_speed)
|
|
||||||
)
|
|
||||||
|
|
||||||
async def async_set_power_belief(self, power_state: bool) -> None:
|
async def async_set_power_belief(self, power_state: bool) -> None:
|
||||||
"""Set the believed state to on or off."""
|
"""Set the believed state to on or off."""
|
||||||
try:
|
try:
|
||||||
await self._hub.bond.action(
|
await self._bond.action(
|
||||||
self._device.device_id, Action.set_power_state_belief(power_state)
|
self._device_id, Action.set_power_state_belief(power_state)
|
||||||
)
|
)
|
||||||
except ClientResponseError as ex:
|
except ClientResponseError as ex:
|
||||||
raise HomeAssistantError(
|
raise HomeAssistantError(
|
||||||
@ -168,8 +163,8 @@ class BondFan(BondEntity, FanEntity):
|
|||||||
bond_speed,
|
bond_speed,
|
||||||
)
|
)
|
||||||
try:
|
try:
|
||||||
await self._hub.bond.action(
|
await self._bond.action(
|
||||||
self._device.device_id, Action.set_speed_belief(bond_speed)
|
self._device_id, Action.set_speed_belief(bond_speed)
|
||||||
)
|
)
|
||||||
except ClientResponseError as ex:
|
except ClientResponseError as ex:
|
||||||
raise HomeAssistantError(
|
raise HomeAssistantError(
|
||||||
@ -191,25 +186,21 @@ class BondFan(BondEntity, FanEntity):
|
|||||||
elif percentage is not None:
|
elif percentage is not None:
|
||||||
await self.async_set_percentage(percentage)
|
await self.async_set_percentage(percentage)
|
||||||
else:
|
else:
|
||||||
await self._hub.bond.action(self._device.device_id, Action.turn_on())
|
await self._bond.action(self._device_id, Action.turn_on())
|
||||||
|
|
||||||
async def async_set_preset_mode(self, preset_mode: str) -> None:
|
async def async_set_preset_mode(self, preset_mode: str) -> None:
|
||||||
"""Set the preset mode of the fan."""
|
"""Set the preset mode of the fan."""
|
||||||
await self._hub.bond.action(self._device.device_id, Action(Action.BREEZE_ON))
|
await self._bond.action(self._device_id, Action(Action.BREEZE_ON))
|
||||||
|
|
||||||
async def async_turn_off(self, **kwargs: Any) -> None:
|
async def async_turn_off(self, **kwargs: Any) -> None:
|
||||||
"""Turn the fan off."""
|
"""Turn the fan off."""
|
||||||
if self.preset_mode == PRESET_MODE_BREEZE:
|
if self.preset_mode == PRESET_MODE_BREEZE:
|
||||||
await self._hub.bond.action(
|
await self._bond.action(self._device_id, Action(Action.BREEZE_OFF))
|
||||||
self._device.device_id, Action(Action.BREEZE_OFF)
|
await self._bond.action(self._device_id, Action.turn_off())
|
||||||
)
|
|
||||||
await self._hub.bond.action(self._device.device_id, Action.turn_off())
|
|
||||||
|
|
||||||
async def async_set_direction(self, direction: str) -> None:
|
async def async_set_direction(self, direction: str) -> None:
|
||||||
"""Set fan rotation direction."""
|
"""Set fan rotation direction."""
|
||||||
bond_direction = (
|
bond_direction = (
|
||||||
Direction.REVERSE if direction == DIRECTION_REVERSE else Direction.FORWARD
|
Direction.REVERSE if direction == DIRECTION_REVERSE else Direction.FORWARD
|
||||||
)
|
)
|
||||||
await self._hub.bond.action(
|
await self._bond.action(self._device_id, Action.set_direction(bond_direction))
|
||||||
self._device.device_id, Action.set_direction(bond_direction)
|
|
||||||
)
|
|
||||||
|
@ -6,7 +6,7 @@ import logging
|
|||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
from aiohttp.client_exceptions import ClientResponseError
|
from aiohttp.client_exceptions import ClientResponseError
|
||||||
from bond_async import Action, BPUPSubscriptions, DeviceType
|
from bond_async import Action, DeviceType
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
from homeassistant.components.light import ATTR_BRIGHTNESS, ColorMode, LightEntity
|
from homeassistant.components.light import ATTR_BRIGHTNESS, ColorMode, LightEntity
|
||||||
@ -23,7 +23,8 @@ from .const import (
|
|||||||
SERVICE_SET_LIGHT_POWER_TRACKED_STATE,
|
SERVICE_SET_LIGHT_POWER_TRACKED_STATE,
|
||||||
)
|
)
|
||||||
from .entity import BondEntity
|
from .entity import BondEntity
|
||||||
from .utils import BondDevice, BondHub
|
from .models import BondData
|
||||||
|
from .utils import BondDevice
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
@ -46,8 +47,6 @@ async def async_setup_entry(
|
|||||||
"""Set up Bond light devices."""
|
"""Set up Bond light devices."""
|
||||||
data = entry.runtime_data
|
data = entry.runtime_data
|
||||||
hub = data.hub
|
hub = data.hub
|
||||||
bpup_subs = data.bpup_subs
|
|
||||||
platform = entity_platform.async_get_current_platform()
|
|
||||||
|
|
||||||
platform = entity_platform.async_get_current_platform()
|
platform = entity_platform.async_get_current_platform()
|
||||||
for service in ENTITY_SERVICES:
|
for service in ENTITY_SERVICES:
|
||||||
@ -58,7 +57,7 @@ async def async_setup_entry(
|
|||||||
)
|
)
|
||||||
|
|
||||||
fan_lights: list[Entity] = [
|
fan_lights: list[Entity] = [
|
||||||
BondLight(hub, device, bpup_subs)
|
BondLight(data, device)
|
||||||
for device in hub.devices
|
for device in hub.devices
|
||||||
if DeviceType.is_fan(device.type)
|
if DeviceType.is_fan(device.type)
|
||||||
and device.supports_light()
|
and device.supports_light()
|
||||||
@ -66,31 +65,31 @@ async def async_setup_entry(
|
|||||||
]
|
]
|
||||||
|
|
||||||
fan_up_lights: list[Entity] = [
|
fan_up_lights: list[Entity] = [
|
||||||
BondUpLight(hub, device, bpup_subs, "up_light")
|
BondUpLight(data, device, "up_light")
|
||||||
for device in hub.devices
|
for device in hub.devices
|
||||||
if DeviceType.is_fan(device.type) and device.supports_up_light()
|
if DeviceType.is_fan(device.type) and device.supports_up_light()
|
||||||
]
|
]
|
||||||
|
|
||||||
fan_down_lights: list[Entity] = [
|
fan_down_lights: list[Entity] = [
|
||||||
BondDownLight(hub, device, bpup_subs, "down_light")
|
BondDownLight(data, device, "down_light")
|
||||||
for device in hub.devices
|
for device in hub.devices
|
||||||
if DeviceType.is_fan(device.type) and device.supports_down_light()
|
if DeviceType.is_fan(device.type) and device.supports_down_light()
|
||||||
]
|
]
|
||||||
|
|
||||||
fireplaces: list[Entity] = [
|
fireplaces: list[Entity] = [
|
||||||
BondFireplace(hub, device, bpup_subs)
|
BondFireplace(data, device)
|
||||||
for device in hub.devices
|
for device in hub.devices
|
||||||
if DeviceType.is_fireplace(device.type)
|
if DeviceType.is_fireplace(device.type)
|
||||||
]
|
]
|
||||||
|
|
||||||
fp_lights: list[Entity] = [
|
fp_lights: list[Entity] = [
|
||||||
BondLight(hub, device, bpup_subs, "light")
|
BondLight(data, device, "light")
|
||||||
for device in hub.devices
|
for device in hub.devices
|
||||||
if DeviceType.is_fireplace(device.type) and device.supports_light()
|
if DeviceType.is_fireplace(device.type) and device.supports_light()
|
||||||
]
|
]
|
||||||
|
|
||||||
lights: list[Entity] = [
|
lights: list[Entity] = [
|
||||||
BondLight(hub, device, bpup_subs)
|
BondLight(data, device)
|
||||||
for device in hub.devices
|
for device in hub.devices
|
||||||
if DeviceType.is_light(device.type)
|
if DeviceType.is_light(device.type)
|
||||||
]
|
]
|
||||||
@ -130,8 +129,8 @@ class BondBaseLight(BondEntity, LightEntity):
|
|||||||
await self.async_set_power_belief(False)
|
await self.async_set_power_belief(False)
|
||||||
return
|
return
|
||||||
try:
|
try:
|
||||||
await self._hub.bond.action(
|
await self._bond.action(
|
||||||
self._device.device_id,
|
self._device_id,
|
||||||
Action.set_brightness_belief(round((brightness * 100) / 255)),
|
Action.set_brightness_belief(round((brightness * 100) / 255)),
|
||||||
)
|
)
|
||||||
except ClientResponseError as ex:
|
except ClientResponseError as ex:
|
||||||
@ -143,8 +142,8 @@ class BondBaseLight(BondEntity, LightEntity):
|
|||||||
async def async_set_power_belief(self, power_state: bool) -> None:
|
async def async_set_power_belief(self, power_state: bool) -> None:
|
||||||
"""Set the belief state of the light."""
|
"""Set the belief state of the light."""
|
||||||
try:
|
try:
|
||||||
await self._hub.bond.action(
|
await self._bond.action(
|
||||||
self._device.device_id, Action.set_light_state_belief(power_state)
|
self._device_id, Action.set_light_state_belief(power_state)
|
||||||
)
|
)
|
||||||
except ClientResponseError as ex:
|
except ClientResponseError as ex:
|
||||||
raise HomeAssistantError(
|
raise HomeAssistantError(
|
||||||
@ -158,13 +157,12 @@ class BondLight(BondBaseLight, BondEntity, LightEntity):
|
|||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
hub: BondHub,
|
data: BondData,
|
||||||
device: BondDevice,
|
device: BondDevice,
|
||||||
bpup_subs: BPUPSubscriptions,
|
|
||||||
sub_device: str | None = None,
|
sub_device: str | None = None,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Create HA entity representing Bond light."""
|
"""Create HA entity representing Bond light."""
|
||||||
super().__init__(hub, device, bpup_subs, sub_device)
|
super().__init__(data, device, sub_device)
|
||||||
if device.supports_set_brightness():
|
if device.supports_set_brightness():
|
||||||
self._attr_color_mode = ColorMode.BRIGHTNESS
|
self._attr_color_mode = ColorMode.BRIGHTNESS
|
||||||
self._attr_supported_color_modes = {ColorMode.BRIGHTNESS}
|
self._attr_supported_color_modes = {ColorMode.BRIGHTNESS}
|
||||||
@ -178,16 +176,16 @@ class BondLight(BondBaseLight, BondEntity, LightEntity):
|
|||||||
async def async_turn_on(self, **kwargs: Any) -> None:
|
async def async_turn_on(self, **kwargs: Any) -> None:
|
||||||
"""Turn on the light."""
|
"""Turn on the light."""
|
||||||
if brightness := kwargs.get(ATTR_BRIGHTNESS):
|
if brightness := kwargs.get(ATTR_BRIGHTNESS):
|
||||||
await self._hub.bond.action(
|
await self._bond.action(
|
||||||
self._device.device_id,
|
self._device_id,
|
||||||
Action.set_brightness(round((brightness * 100) / 255)),
|
Action.set_brightness(round((brightness * 100) / 255)),
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
await self._hub.bond.action(self._device.device_id, Action.turn_light_on())
|
await self._bond.action(self._device_id, Action.turn_light_on())
|
||||||
|
|
||||||
async def async_turn_off(self, **kwargs: Any) -> None:
|
async def async_turn_off(self, **kwargs: Any) -> None:
|
||||||
"""Turn off the light."""
|
"""Turn off the light."""
|
||||||
await self._hub.bond.action(self._device.device_id, Action.turn_light_off())
|
await self._bond.action(self._device_id, Action.turn_light_off())
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
def _async_has_action_or_raise(self, action: str) -> None:
|
def _async_has_action_or_raise(self, action: str) -> None:
|
||||||
@ -202,8 +200,8 @@ class BondLight(BondBaseLight, BondEntity, LightEntity):
|
|||||||
" replaced with a button; Call the button.press service instead"
|
" replaced with a button; Call the button.press service instead"
|
||||||
)
|
)
|
||||||
self._async_has_action_or_raise(Action.START_INCREASING_BRIGHTNESS)
|
self._async_has_action_or_raise(Action.START_INCREASING_BRIGHTNESS)
|
||||||
await self._hub.bond.action(
|
await self._bond.action(
|
||||||
self._device.device_id, Action(Action.START_INCREASING_BRIGHTNESS)
|
self._device_id, Action(Action.START_INCREASING_BRIGHTNESS)
|
||||||
)
|
)
|
||||||
|
|
||||||
async def async_start_decreasing_brightness(self) -> None:
|
async def async_start_decreasing_brightness(self) -> None:
|
||||||
@ -213,8 +211,8 @@ class BondLight(BondBaseLight, BondEntity, LightEntity):
|
|||||||
" replaced with a button; Call the button.press service instead"
|
" replaced with a button; Call the button.press service instead"
|
||||||
)
|
)
|
||||||
self._async_has_action_or_raise(Action.START_DECREASING_BRIGHTNESS)
|
self._async_has_action_or_raise(Action.START_DECREASING_BRIGHTNESS)
|
||||||
await self._hub.bond.action(
|
await self._bond.action(
|
||||||
self._device.device_id, Action(Action.START_DECREASING_BRIGHTNESS)
|
self._device_id, Action(Action.START_DECREASING_BRIGHTNESS)
|
||||||
)
|
)
|
||||||
|
|
||||||
async def async_stop(self) -> None:
|
async def async_stop(self) -> None:
|
||||||
@ -224,7 +222,7 @@ class BondLight(BondBaseLight, BondEntity, LightEntity):
|
|||||||
" Call the button.press service instead"
|
" Call the button.press service instead"
|
||||||
)
|
)
|
||||||
self._async_has_action_or_raise(Action.STOP)
|
self._async_has_action_or_raise(Action.STOP)
|
||||||
await self._hub.bond.action(self._device.device_id, Action(Action.STOP))
|
await self._bond.action(self._device_id, Action(Action.STOP))
|
||||||
|
|
||||||
|
|
||||||
class BondDownLight(BondBaseLight, BondEntity, LightEntity):
|
class BondDownLight(BondBaseLight, BondEntity, LightEntity):
|
||||||
@ -236,15 +234,11 @@ class BondDownLight(BondBaseLight, BondEntity, LightEntity):
|
|||||||
|
|
||||||
async def async_turn_on(self, **kwargs: Any) -> None:
|
async def async_turn_on(self, **kwargs: Any) -> None:
|
||||||
"""Turn on the light."""
|
"""Turn on the light."""
|
||||||
await self._hub.bond.action(
|
await self._bond.action(self._device_id, Action(Action.TURN_DOWN_LIGHT_ON))
|
||||||
self._device.device_id, Action(Action.TURN_DOWN_LIGHT_ON)
|
|
||||||
)
|
|
||||||
|
|
||||||
async def async_turn_off(self, **kwargs: Any) -> None:
|
async def async_turn_off(self, **kwargs: Any) -> None:
|
||||||
"""Turn off the light."""
|
"""Turn off the light."""
|
||||||
await self._hub.bond.action(
|
await self._bond.action(self._device_id, Action(Action.TURN_DOWN_LIGHT_OFF))
|
||||||
self._device.device_id, Action(Action.TURN_DOWN_LIGHT_OFF)
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
class BondUpLight(BondBaseLight, BondEntity, LightEntity):
|
class BondUpLight(BondBaseLight, BondEntity, LightEntity):
|
||||||
@ -256,15 +250,11 @@ class BondUpLight(BondBaseLight, BondEntity, LightEntity):
|
|||||||
|
|
||||||
async def async_turn_on(self, **kwargs: Any) -> None:
|
async def async_turn_on(self, **kwargs: Any) -> None:
|
||||||
"""Turn on the light."""
|
"""Turn on the light."""
|
||||||
await self._hub.bond.action(
|
await self._bond.action(self._device_id, Action(Action.TURN_UP_LIGHT_ON))
|
||||||
self._device.device_id, Action(Action.TURN_UP_LIGHT_ON)
|
|
||||||
)
|
|
||||||
|
|
||||||
async def async_turn_off(self, **kwargs: Any) -> None:
|
async def async_turn_off(self, **kwargs: Any) -> None:
|
||||||
"""Turn off the light."""
|
"""Turn off the light."""
|
||||||
await self._hub.bond.action(
|
await self._bond.action(self._device_id, Action(Action.TURN_UP_LIGHT_OFF))
|
||||||
self._device.device_id, Action(Action.TURN_UP_LIGHT_OFF)
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
class BondFireplace(BondEntity, LightEntity):
|
class BondFireplace(BondEntity, LightEntity):
|
||||||
@ -287,15 +277,15 @@ class BondFireplace(BondEntity, LightEntity):
|
|||||||
|
|
||||||
if brightness := kwargs.get(ATTR_BRIGHTNESS):
|
if brightness := kwargs.get(ATTR_BRIGHTNESS):
|
||||||
flame = round((brightness * 100) / 255)
|
flame = round((brightness * 100) / 255)
|
||||||
await self._hub.bond.action(self._device.device_id, Action.set_flame(flame))
|
await self._bond.action(self._device_id, Action.set_flame(flame))
|
||||||
else:
|
else:
|
||||||
await self._hub.bond.action(self._device.device_id, Action.turn_on())
|
await self._bond.action(self._device_id, Action.turn_on())
|
||||||
|
|
||||||
async def async_turn_off(self, **kwargs: Any) -> None:
|
async def async_turn_off(self, **kwargs: Any) -> None:
|
||||||
"""Turn the fireplace off."""
|
"""Turn the fireplace off."""
|
||||||
_LOGGER.debug("Fireplace async_turn_off called with: %s", kwargs)
|
_LOGGER.debug("Fireplace async_turn_off called with: %s", kwargs)
|
||||||
|
|
||||||
await self._hub.bond.action(self._device.device_id, Action.turn_off())
|
await self._bond.action(self._device_id, Action.turn_off())
|
||||||
|
|
||||||
async def async_set_brightness_belief(self, brightness: int) -> None:
|
async def async_set_brightness_belief(self, brightness: int) -> None:
|
||||||
"""Set the belief state of the light."""
|
"""Set the belief state of the light."""
|
||||||
@ -305,8 +295,8 @@ class BondFireplace(BondEntity, LightEntity):
|
|||||||
await self.async_set_power_belief(False)
|
await self.async_set_power_belief(False)
|
||||||
return
|
return
|
||||||
try:
|
try:
|
||||||
await self._hub.bond.action(
|
await self._bond.action(
|
||||||
self._device.device_id,
|
self._device_id,
|
||||||
Action.set_brightness_belief(round((brightness * 100) / 255)),
|
Action.set_brightness_belief(round((brightness * 100) / 255)),
|
||||||
)
|
)
|
||||||
except ClientResponseError as ex:
|
except ClientResponseError as ex:
|
||||||
@ -318,8 +308,8 @@ class BondFireplace(BondEntity, LightEntity):
|
|||||||
async def async_set_power_belief(self, power_state: bool) -> None:
|
async def async_set_power_belief(self, power_state: bool) -> None:
|
||||||
"""Set the belief state of the light."""
|
"""Set the belief state of the light."""
|
||||||
try:
|
try:
|
||||||
await self._hub.bond.action(
|
await self._bond.action(
|
||||||
self._device.device_id, Action.set_power_state_belief(power_state)
|
self._device_id, Action.set_power_state_belief(power_state)
|
||||||
)
|
)
|
||||||
except ClientResponseError as ex:
|
except ClientResponseError as ex:
|
||||||
raise HomeAssistantError(
|
raise HomeAssistantError(
|
||||||
|
@ -26,8 +26,6 @@ async def async_setup_entry(
|
|||||||
) -> None:
|
) -> None:
|
||||||
"""Set up Bond generic devices."""
|
"""Set up Bond generic devices."""
|
||||||
data = entry.runtime_data
|
data = entry.runtime_data
|
||||||
hub = data.hub
|
|
||||||
bpup_subs = data.bpup_subs
|
|
||||||
platform = entity_platform.async_get_current_platform()
|
platform = entity_platform.async_get_current_platform()
|
||||||
platform.async_register_entity_service(
|
platform.async_register_entity_service(
|
||||||
SERVICE_SET_POWER_TRACKED_STATE,
|
SERVICE_SET_POWER_TRACKED_STATE,
|
||||||
@ -36,8 +34,8 @@ async def async_setup_entry(
|
|||||||
)
|
)
|
||||||
|
|
||||||
async_add_entities(
|
async_add_entities(
|
||||||
BondSwitch(hub, device, bpup_subs)
|
BondSwitch(data, device)
|
||||||
for device in hub.devices
|
for device in data.hub.devices
|
||||||
if DeviceType.is_generic(device.type)
|
if DeviceType.is_generic(device.type)
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -50,17 +48,17 @@ class BondSwitch(BondEntity, SwitchEntity):
|
|||||||
|
|
||||||
async def async_turn_on(self, **kwargs: Any) -> None:
|
async def async_turn_on(self, **kwargs: Any) -> None:
|
||||||
"""Turn the device on."""
|
"""Turn the device on."""
|
||||||
await self._hub.bond.action(self._device.device_id, Action.turn_on())
|
await self._bond.action(self._device_id, Action.turn_on())
|
||||||
|
|
||||||
async def async_turn_off(self, **kwargs: Any) -> None:
|
async def async_turn_off(self, **kwargs: Any) -> None:
|
||||||
"""Turn the device off."""
|
"""Turn the device off."""
|
||||||
await self._hub.bond.action(self._device.device_id, Action.turn_off())
|
await self._bond.action(self._device_id, Action.turn_off())
|
||||||
|
|
||||||
async def async_set_power_belief(self, power_state: bool) -> None:
|
async def async_set_power_belief(self, power_state: bool) -> None:
|
||||||
"""Set switch power belief."""
|
"""Set switch power belief."""
|
||||||
try:
|
try:
|
||||||
await self._hub.bond.action(
|
await self._bond.action(
|
||||||
self._device.device_id, Action.set_power_state_belief(power_state)
|
self._device_id, Action.set_power_state_belief(power_state)
|
||||||
)
|
)
|
||||||
except ClientResponseError as ex:
|
except ClientResponseError as ex:
|
||||||
raise HomeAssistantError(
|
raise HomeAssistantError(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user