mirror of
https://github.com/home-assistant/core.git
synced 2025-07-13 08:17:08 +00:00
Remove the LIFX sensor update coordinator (#90740)
This commit is contained in:
parent
a58b3721ed
commit
5e7e96c5da
@ -210,7 +210,6 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|||||||
coordinator.async_setup()
|
coordinator.async_setup()
|
||||||
try:
|
try:
|
||||||
await coordinator.async_config_entry_first_refresh()
|
await coordinator.async_config_entry_first_refresh()
|
||||||
await coordinator.sensor_coordinator.async_config_entry_first_refresh()
|
|
||||||
except ConfigEntryNotReady:
|
except ConfigEntryNotReady:
|
||||||
connection.async_stop()
|
connection.async_stop()
|
||||||
raise
|
raise
|
||||||
|
@ -12,8 +12,8 @@ from homeassistant.core import HomeAssistant, callback
|
|||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
|
|
||||||
from .const import DOMAIN, HEV_CYCLE_STATE
|
from .const import DOMAIN, HEV_CYCLE_STATE
|
||||||
from .coordinator import LIFXSensorUpdateCoordinator, LIFXUpdateCoordinator
|
from .coordinator import LIFXUpdateCoordinator
|
||||||
from .entity import LIFXSensorEntity
|
from .entity import LIFXEntity
|
||||||
from .util import lifx_features
|
from .util import lifx_features
|
||||||
|
|
||||||
HEV_CYCLE_STATE_SENSOR = BinarySensorEntityDescription(
|
HEV_CYCLE_STATE_SENSOR = BinarySensorEntityDescription(
|
||||||
@ -32,29 +32,24 @@ async def async_setup_entry(
|
|||||||
|
|
||||||
if lifx_features(coordinator.device)["hev"]:
|
if lifx_features(coordinator.device)["hev"]:
|
||||||
async_add_entities(
|
async_add_entities(
|
||||||
[
|
[LIFXHevCycleBinarySensorEntity(coordinator, HEV_CYCLE_STATE_SENSOR)]
|
||||||
LIFXHevCycleBinarySensorEntity(
|
|
||||||
coordinator=coordinator.sensor_coordinator,
|
|
||||||
description=HEV_CYCLE_STATE_SENSOR,
|
|
||||||
)
|
|
||||||
]
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class LIFXHevCycleBinarySensorEntity(LIFXSensorEntity, BinarySensorEntity):
|
class LIFXHevCycleBinarySensorEntity(LIFXEntity, BinarySensorEntity):
|
||||||
"""LIFX HEV cycle state binary sensor."""
|
"""LIFX HEV cycle state binary sensor."""
|
||||||
|
|
||||||
_attr_has_entity_name = True
|
_attr_has_entity_name = True
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
coordinator: LIFXSensorUpdateCoordinator,
|
coordinator: LIFXUpdateCoordinator,
|
||||||
description: BinarySensorEntityDescription,
|
description: BinarySensorEntityDescription,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Initialise the sensor."""
|
"""Initialise the sensor."""
|
||||||
super().__init__(coordinator)
|
super().__init__(coordinator)
|
||||||
self.entity_description = description
|
self.entity_description = description
|
||||||
self._attr_unique_id = f"{coordinator.parent.serial_number}_{description.key}"
|
self._attr_unique_id = f"{coordinator.serial_number}_{description.key}"
|
||||||
self._async_update_attrs()
|
self._async_update_attrs()
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
|
@ -12,8 +12,8 @@ from homeassistant.core import HomeAssistant
|
|||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
|
|
||||||
from .const import DOMAIN, IDENTIFY, RESTART
|
from .const import DOMAIN, IDENTIFY, RESTART
|
||||||
from .coordinator import LIFXSensorUpdateCoordinator, LIFXUpdateCoordinator
|
from .coordinator import LIFXUpdateCoordinator
|
||||||
from .entity import LIFXSensorEntity
|
from .entity import LIFXEntity
|
||||||
|
|
||||||
RESTART_BUTTON_DESCRIPTION = ButtonEntityDescription(
|
RESTART_BUTTON_DESCRIPTION = ButtonEntityDescription(
|
||||||
key=RESTART,
|
key=RESTART,
|
||||||
@ -38,22 +38,21 @@ async def async_setup_entry(
|
|||||||
domain_data = hass.data[DOMAIN]
|
domain_data = hass.data[DOMAIN]
|
||||||
coordinator: LIFXUpdateCoordinator = domain_data[entry.entry_id]
|
coordinator: LIFXUpdateCoordinator = domain_data[entry.entry_id]
|
||||||
async_add_entities(
|
async_add_entities(
|
||||||
cls(coordinator.sensor_coordinator)
|
[LIFXRestartButton(coordinator), LIFXIdentifyButton(coordinator)]
|
||||||
for cls in (LIFXRestartButton, LIFXIdentifyButton)
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class LIFXButton(LIFXSensorEntity, ButtonEntity):
|
class LIFXButton(LIFXEntity, ButtonEntity):
|
||||||
"""Base LIFX button."""
|
"""Base LIFX button."""
|
||||||
|
|
||||||
_attr_has_entity_name: bool = True
|
_attr_has_entity_name: bool = True
|
||||||
_attr_should_poll: bool = False
|
_attr_should_poll: bool = False
|
||||||
|
|
||||||
def __init__(self, coordinator: LIFXSensorUpdateCoordinator) -> None:
|
def __init__(self, coordinator: LIFXUpdateCoordinator) -> None:
|
||||||
"""Initialise a LIFX button."""
|
"""Initialise a LIFX button."""
|
||||||
super().__init__(coordinator)
|
super().__init__(coordinator)
|
||||||
self._attr_unique_id = (
|
self._attr_unique_id = (
|
||||||
f"{coordinator.parent.serial_number}_{self.entity_description.key}"
|
f"{coordinator.serial_number}_{self.entity_description.key}"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -79,7 +79,9 @@ class LIFXUpdateCoordinator(DataUpdateCoordinator[None]):
|
|||||||
self.device: Light = connection.device
|
self.device: Light = connection.device
|
||||||
self.lock = asyncio.Lock()
|
self.lock = asyncio.Lock()
|
||||||
self.active_effect = FirmwareEffect.OFF
|
self.active_effect = FirmwareEffect.OFF
|
||||||
self.sensor_coordinator = LIFXSensorUpdateCoordinator(hass, self, title)
|
self._update_rssi: bool = False
|
||||||
|
self._rssi: int = 0
|
||||||
|
self.last_used_theme: str = ""
|
||||||
|
|
||||||
super().__init__(
|
super().__init__(
|
||||||
hass,
|
hass,
|
||||||
@ -100,6 +102,24 @@ class LIFXUpdateCoordinator(DataUpdateCoordinator[None]):
|
|||||||
self.device.retry_count = MESSAGE_RETRIES
|
self.device.retry_count = MESSAGE_RETRIES
|
||||||
self.device.unregister_timeout = UNAVAILABLE_GRACE
|
self.device.unregister_timeout = UNAVAILABLE_GRACE
|
||||||
|
|
||||||
|
@property
|
||||||
|
def rssi(self) -> int:
|
||||||
|
"""Return stored RSSI value."""
|
||||||
|
return self._rssi
|
||||||
|
|
||||||
|
@property
|
||||||
|
def rssi_uom(self) -> str:
|
||||||
|
"""Return the RSSI unit of measurement."""
|
||||||
|
if AwesomeVersion(self.device.host_firmware_version) <= RSSI_DBM_FW:
|
||||||
|
return SIGNAL_STRENGTH_DECIBELS
|
||||||
|
|
||||||
|
return SIGNAL_STRENGTH_DECIBELS_MILLIWATT
|
||||||
|
|
||||||
|
@property
|
||||||
|
def current_infrared_brightness(self) -> str | None:
|
||||||
|
"""Return the current infrared brightness as a string."""
|
||||||
|
return infrared_brightness_value_to_option(self.device.infrared_brightness)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def serial_number(self) -> str:
|
def serial_number(self) -> str:
|
||||||
"""Return the internal mac address."""
|
"""Return the internal mac address."""
|
||||||
@ -187,6 +207,9 @@ class LIFXUpdateCoordinator(DataUpdateCoordinator[None]):
|
|||||||
if self.device.mac_addr == TARGET_ANY:
|
if self.device.mac_addr == TARGET_ANY:
|
||||||
self.device.mac_addr = response.target_addr
|
self.device.mac_addr = response.target_addr
|
||||||
|
|
||||||
|
if self._update_rssi is True:
|
||||||
|
await self.async_update_rssi()
|
||||||
|
|
||||||
# Update extended multizone devices
|
# Update extended multizone devices
|
||||||
if lifx_features(self.device)["extended_multizone"]:
|
if lifx_features(self.device)["extended_multizone"]:
|
||||||
await self.async_get_extended_color_zones()
|
await self.async_get_extended_color_zones()
|
||||||
@ -196,6 +219,12 @@ class LIFXUpdateCoordinator(DataUpdateCoordinator[None]):
|
|||||||
await self.async_get_color_zones()
|
await self.async_get_color_zones()
|
||||||
await self.async_get_multizone_effect()
|
await self.async_get_multizone_effect()
|
||||||
|
|
||||||
|
if lifx_features(self.device)["hev"]:
|
||||||
|
await self.async_get_hev_cycle()
|
||||||
|
|
||||||
|
if lifx_features(self.device)["infrared"]:
|
||||||
|
await async_execute_lifx(self.device.get_infrared)
|
||||||
|
|
||||||
async def async_get_color_zones(self) -> None:
|
async def async_get_color_zones(self) -> None:
|
||||||
"""Get updated color information for each zone."""
|
"""Get updated color information for each zone."""
|
||||||
zone = 0
|
zone = 0
|
||||||
@ -357,64 +386,6 @@ class LIFXUpdateCoordinator(DataUpdateCoordinator[None]):
|
|||||||
"""Return the enum value of the currently active firmware effect."""
|
"""Return the enum value of the currently active firmware effect."""
|
||||||
return self.active_effect.value
|
return self.active_effect.value
|
||||||
|
|
||||||
|
|
||||||
class LIFXSensorUpdateCoordinator(DataUpdateCoordinator[None]):
|
|
||||||
"""DataUpdateCoordinator to gather data for a specific lifx device."""
|
|
||||||
|
|
||||||
def __init__(
|
|
||||||
self,
|
|
||||||
hass: HomeAssistant,
|
|
||||||
parent: LIFXUpdateCoordinator,
|
|
||||||
title: str,
|
|
||||||
) -> None:
|
|
||||||
"""Initialize DataUpdateCoordinator."""
|
|
||||||
self.parent: LIFXUpdateCoordinator = parent
|
|
||||||
self.device: Light = parent.device
|
|
||||||
self._update_rssi: bool = False
|
|
||||||
self._rssi: int = 0
|
|
||||||
self.last_used_theme: str = ""
|
|
||||||
|
|
||||||
super().__init__(
|
|
||||||
hass,
|
|
||||||
_LOGGER,
|
|
||||||
name=f"{title} Sensors ({self.device.ip_addr})",
|
|
||||||
update_interval=timedelta(seconds=SENSOR_UPDATE_INTERVAL),
|
|
||||||
# Refresh immediately because the changes are not visible
|
|
||||||
request_refresh_debouncer=Debouncer(
|
|
||||||
hass, _LOGGER, cooldown=0, immediate=True
|
|
||||||
),
|
|
||||||
)
|
|
||||||
|
|
||||||
@property
|
|
||||||
def rssi(self) -> int:
|
|
||||||
"""Return stored RSSI value."""
|
|
||||||
return self._rssi
|
|
||||||
|
|
||||||
@property
|
|
||||||
def rssi_uom(self) -> str:
|
|
||||||
"""Return the RSSI unit of measurement."""
|
|
||||||
if AwesomeVersion(self.device.host_firmware_version) <= RSSI_DBM_FW:
|
|
||||||
return SIGNAL_STRENGTH_DECIBELS
|
|
||||||
|
|
||||||
return SIGNAL_STRENGTH_DECIBELS_MILLIWATT
|
|
||||||
|
|
||||||
@property
|
|
||||||
def current_infrared_brightness(self) -> str | None:
|
|
||||||
"""Return the current infrared brightness as a string."""
|
|
||||||
return infrared_brightness_value_to_option(self.device.infrared_brightness)
|
|
||||||
|
|
||||||
async def _async_update_data(self) -> None:
|
|
||||||
"""Fetch all device data from the api."""
|
|
||||||
|
|
||||||
if self._update_rssi is True:
|
|
||||||
await self.async_update_rssi()
|
|
||||||
|
|
||||||
if lifx_features(self.device)["hev"]:
|
|
||||||
await self.async_get_hev_cycle()
|
|
||||||
|
|
||||||
if lifx_features(self.device)["infrared"]:
|
|
||||||
await async_execute_lifx(self.device.get_infrared)
|
|
||||||
|
|
||||||
async def async_set_infrared_brightness(self, option: str) -> None:
|
async def async_set_infrared_brightness(self, option: str) -> None:
|
||||||
"""Set infrared brightness."""
|
"""Set infrared brightness."""
|
||||||
infrared_brightness = infrared_brightness_option_to_value(option)
|
infrared_brightness = infrared_brightness_option_to_value(option)
|
||||||
@ -425,13 +396,13 @@ class LIFXSensorUpdateCoordinator(DataUpdateCoordinator[None]):
|
|||||||
bulb: Light = self.device
|
bulb: Light = self.device
|
||||||
if bulb.power_level:
|
if bulb.power_level:
|
||||||
# just flash the bulb for three seconds
|
# just flash the bulb for three seconds
|
||||||
await self.parent.async_set_waveform_optional(value=IDENTIFY_WAVEFORM)
|
await self.async_set_waveform_optional(value=IDENTIFY_WAVEFORM)
|
||||||
return
|
return
|
||||||
# Turn the bulb on first, flash for 3 seconds, then turn off
|
# Turn the bulb on first, flash for 3 seconds, then turn off
|
||||||
await self.parent.async_set_power(state=True, duration=1)
|
await self.async_set_power(state=True, duration=1)
|
||||||
await self.parent.async_set_waveform_optional(value=IDENTIFY_WAVEFORM)
|
await self.async_set_waveform_optional(value=IDENTIFY_WAVEFORM)
|
||||||
await asyncio.sleep(LIFX_IDENTIFY_DELAY)
|
await asyncio.sleep(LIFX_IDENTIFY_DELAY)
|
||||||
await self.parent.async_set_power(state=False, duration=1)
|
await self.async_set_power(state=False, duration=1)
|
||||||
|
|
||||||
def async_enable_rssi_updates(self) -> Callable[[], None]:
|
def async_enable_rssi_updates(self) -> Callable[[], None]:
|
||||||
"""Enable RSSI signal strength updates."""
|
"""Enable RSSI signal strength updates."""
|
||||||
@ -471,4 +442,4 @@ class LIFXSensorUpdateCoordinator(DataUpdateCoordinator[None]):
|
|||||||
"""Apply the selected theme to the device."""
|
"""Apply the selected theme to the device."""
|
||||||
self.last_used_theme = theme_name
|
self.last_used_theme = theme_name
|
||||||
theme = ThemeLibrary().get_theme(theme_name)
|
theme = ThemeLibrary().get_theme(theme_name)
|
||||||
await ThemePainter(self.hass.loop).paint(theme, [self.parent.device])
|
await ThemePainter(self.hass.loop).paint(theme, [self.device])
|
||||||
|
@ -8,7 +8,7 @@ from homeassistant.helpers.entity import DeviceInfo
|
|||||||
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
||||||
|
|
||||||
from .const import DOMAIN
|
from .const import DOMAIN
|
||||||
from .coordinator import LIFXSensorUpdateCoordinator, LIFXUpdateCoordinator
|
from .coordinator import LIFXUpdateCoordinator
|
||||||
|
|
||||||
|
|
||||||
class LIFXEntity(CoordinatorEntity[LIFXUpdateCoordinator]):
|
class LIFXEntity(CoordinatorEntity[LIFXUpdateCoordinator]):
|
||||||
@ -27,21 +27,3 @@ class LIFXEntity(CoordinatorEntity[LIFXUpdateCoordinator]):
|
|||||||
sw_version=self.bulb.host_firmware_version,
|
sw_version=self.bulb.host_firmware_version,
|
||||||
suggested_area=self.bulb.group,
|
suggested_area=self.bulb.group,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class LIFXSensorEntity(CoordinatorEntity[LIFXSensorUpdateCoordinator]):
|
|
||||||
"""Representation of a LIFX sensor entity with a sensor coordinator."""
|
|
||||||
|
|
||||||
def __init__(self, coordinator: LIFXSensorUpdateCoordinator) -> None:
|
|
||||||
"""Initialise the sensor."""
|
|
||||||
super().__init__(coordinator)
|
|
||||||
self.bulb = coordinator.parent.device
|
|
||||||
self._attr_device_info = DeviceInfo(
|
|
||||||
identifiers={(DOMAIN, coordinator.parent.serial_number)},
|
|
||||||
connections={(dr.CONNECTION_NETWORK_MAC, coordinator.parent.mac_address)},
|
|
||||||
manufacturer="LIFX",
|
|
||||||
name=coordinator.parent.label,
|
|
||||||
model=products.product_map.get(self.bulb.product, "LIFX Bulb"),
|
|
||||||
sw_version=self.bulb.host_firmware_version,
|
|
||||||
suggested_area=self.bulb.group,
|
|
||||||
)
|
|
||||||
|
@ -274,9 +274,7 @@ class LIFXLight(LIFXEntity, LightEntity):
|
|||||||
"This device does not support setting HEV cycle state"
|
"This device does not support setting HEV cycle state"
|
||||||
)
|
)
|
||||||
|
|
||||||
await self.coordinator.sensor_coordinator.async_set_hev_cycle_state(
|
await self.coordinator.async_set_hev_cycle_state(power, duration or 0)
|
||||||
power, duration or 0
|
|
||||||
)
|
|
||||||
await self.update_during_transition(duration or 0)
|
await self.update_during_transition(duration or 0)
|
||||||
|
|
||||||
async def set_power(
|
async def set_power(
|
||||||
|
@ -15,8 +15,8 @@ from .const import (
|
|||||||
INFRARED_BRIGHTNESS,
|
INFRARED_BRIGHTNESS,
|
||||||
INFRARED_BRIGHTNESS_VALUES_MAP,
|
INFRARED_BRIGHTNESS_VALUES_MAP,
|
||||||
)
|
)
|
||||||
from .coordinator import LIFXSensorUpdateCoordinator, LIFXUpdateCoordinator
|
from .coordinator import LIFXUpdateCoordinator
|
||||||
from .entity import LIFXSensorEntity
|
from .entity import LIFXEntity
|
||||||
from .util import lifx_features
|
from .util import lifx_features
|
||||||
|
|
||||||
THEME_NAMES = [theme_name.lower() for theme_name in ThemeLibrary().themes]
|
THEME_NAMES = [theme_name.lower() for theme_name in ThemeLibrary().themes]
|
||||||
@ -42,39 +42,33 @@ async def async_setup_entry(
|
|||||||
"""Set up LIFX from a config entry."""
|
"""Set up LIFX from a config entry."""
|
||||||
coordinator: LIFXUpdateCoordinator = hass.data[DOMAIN][entry.entry_id]
|
coordinator: LIFXUpdateCoordinator = hass.data[DOMAIN][entry.entry_id]
|
||||||
|
|
||||||
entities: list[LIFXSensorEntity] = []
|
entities: list[LIFXEntity] = []
|
||||||
|
|
||||||
if lifx_features(coordinator.device)["infrared"]:
|
if lifx_features(coordinator.device)["infrared"]:
|
||||||
entities.append(
|
entities.append(
|
||||||
LIFXInfraredBrightnessSelectEntity(
|
LIFXInfraredBrightnessSelectEntity(coordinator, INFRARED_BRIGHTNESS_ENTITY)
|
||||||
coordinator.sensor_coordinator, description=INFRARED_BRIGHTNESS_ENTITY
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
|
|
||||||
if lifx_features(coordinator.device)["multizone"] is True:
|
if lifx_features(coordinator.device)["multizone"] is True:
|
||||||
entities.append(
|
entities.append(LIFXThemeSelectEntity(coordinator, THEME_ENTITY))
|
||||||
LIFXThemeSelectEntity(
|
|
||||||
coordinator.sensor_coordinator, description=THEME_ENTITY
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
async_add_entities(entities)
|
async_add_entities(entities)
|
||||||
|
|
||||||
|
|
||||||
class LIFXInfraredBrightnessSelectEntity(LIFXSensorEntity, SelectEntity):
|
class LIFXInfraredBrightnessSelectEntity(LIFXEntity, SelectEntity):
|
||||||
"""LIFX Nightvision infrared brightness configuration entity."""
|
"""LIFX Nightvision infrared brightness configuration entity."""
|
||||||
|
|
||||||
_attr_has_entity_name = True
|
_attr_has_entity_name = True
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
coordinator: LIFXSensorUpdateCoordinator,
|
coordinator: LIFXUpdateCoordinator,
|
||||||
description: SelectEntityDescription,
|
description: SelectEntityDescription,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Initialise the IR brightness config entity."""
|
"""Initialise the IR brightness config entity."""
|
||||||
super().__init__(coordinator)
|
super().__init__(coordinator)
|
||||||
self.entity_description = description
|
self.entity_description = description
|
||||||
self._attr_unique_id = f"{coordinator.parent.serial_number}_{description.key}"
|
self._attr_unique_id = f"{coordinator.serial_number}_{description.key}"
|
||||||
self._attr_current_option = coordinator.current_infrared_brightness
|
self._attr_current_option = coordinator.current_infrared_brightness
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
@ -93,21 +87,21 @@ class LIFXInfraredBrightnessSelectEntity(LIFXSensorEntity, SelectEntity):
|
|||||||
await self.coordinator.async_set_infrared_brightness(option)
|
await self.coordinator.async_set_infrared_brightness(option)
|
||||||
|
|
||||||
|
|
||||||
class LIFXThemeSelectEntity(LIFXSensorEntity, SelectEntity):
|
class LIFXThemeSelectEntity(LIFXEntity, SelectEntity):
|
||||||
"""Theme entity for LIFX multizone devices."""
|
"""Theme entity for LIFX multizone devices."""
|
||||||
|
|
||||||
_attr_has_entity_name = True
|
_attr_has_entity_name = True
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
coordinator: LIFXSensorUpdateCoordinator,
|
coordinator: LIFXUpdateCoordinator,
|
||||||
description: SelectEntityDescription,
|
description: SelectEntityDescription,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Initialise the theme selection entity."""
|
"""Initialise the theme selection entity."""
|
||||||
|
|
||||||
super().__init__(coordinator)
|
super().__init__(coordinator)
|
||||||
self.entity_description = description
|
self.entity_description = description
|
||||||
self._attr_unique_id = f"{coordinator.parent.serial_number}_{description.key}"
|
self._attr_unique_id = f"{coordinator.serial_number}_{description.key}"
|
||||||
self._attr_current_option = None
|
self._attr_current_option = None
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
|
@ -15,8 +15,8 @@ from homeassistant.core import HomeAssistant, callback
|
|||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
|
|
||||||
from .const import ATTR_RSSI, DOMAIN
|
from .const import ATTR_RSSI, DOMAIN
|
||||||
from .coordinator import LIFXSensorUpdateCoordinator, LIFXUpdateCoordinator
|
from .coordinator import LIFXUpdateCoordinator
|
||||||
from .entity import LIFXSensorEntity
|
from .entity import LIFXEntity
|
||||||
|
|
||||||
SCAN_INTERVAL = timedelta(seconds=30)
|
SCAN_INTERVAL = timedelta(seconds=30)
|
||||||
|
|
||||||
@ -35,24 +35,24 @@ async def async_setup_entry(
|
|||||||
) -> None:
|
) -> None:
|
||||||
"""Set up LIFX sensor from config entry."""
|
"""Set up LIFX sensor from config entry."""
|
||||||
coordinator: LIFXUpdateCoordinator = hass.data[DOMAIN][entry.entry_id]
|
coordinator: LIFXUpdateCoordinator = hass.data[DOMAIN][entry.entry_id]
|
||||||
async_add_entities([LIFXRssiSensor(coordinator.sensor_coordinator, RSSI_SENSOR)])
|
async_add_entities([LIFXRssiSensor(coordinator, RSSI_SENSOR)])
|
||||||
|
|
||||||
|
|
||||||
class LIFXRssiSensor(LIFXSensorEntity, SensorEntity):
|
class LIFXRssiSensor(LIFXEntity, SensorEntity):
|
||||||
"""LIFX RSSI sensor."""
|
"""LIFX RSSI sensor."""
|
||||||
|
|
||||||
_attr_has_entity_name = True
|
_attr_has_entity_name = True
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
coordinator: LIFXSensorUpdateCoordinator,
|
coordinator: LIFXUpdateCoordinator,
|
||||||
description: SensorEntityDescription,
|
description: SensorEntityDescription,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Initialise the RSSI sensor."""
|
"""Initialise the RSSI sensor."""
|
||||||
|
|
||||||
super().__init__(coordinator)
|
super().__init__(coordinator)
|
||||||
self.entity_description = description
|
self.entity_description = description
|
||||||
self._attr_unique_id = f"{coordinator.parent.serial_number}_{description.key}"
|
self._attr_unique_id = f"{coordinator.serial_number}_{description.key}"
|
||||||
self._attr_native_unit_of_measurement = coordinator.rssi_uom
|
self._attr_native_unit_of_measurement = coordinator.rssi_uom
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
|
@ -254,7 +254,7 @@ def _patch_config_flow_try_connect(
|
|||||||
):
|
):
|
||||||
"""Patch out discovery."""
|
"""Patch out discovery."""
|
||||||
|
|
||||||
class MockLifxConnecton:
|
class MockLifxConnection:
|
||||||
"""Mock lifx discovery."""
|
"""Mock lifx discovery."""
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
@ -275,7 +275,7 @@ def _patch_config_flow_try_connect(
|
|||||||
def _patcher():
|
def _patcher():
|
||||||
with patch(
|
with patch(
|
||||||
"homeassistant.components.lifx.config_flow.LIFXConnection",
|
"homeassistant.components.lifx.config_flow.LIFXConnection",
|
||||||
MockLifxConnecton,
|
MockLifxConnection,
|
||||||
):
|
):
|
||||||
yield
|
yield
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user