8000 Disable polling for all non-light entities · home-assistant/core@4c89314 · GitHub
[go: up one dir, main page]

Skip to content

Commit 4c89314

Browse files
committed
Disable polling for all non-light entities
Signed-off-by: Avi Miller <me@dje.li>
1 parent 88af53c commit 4c89314

File tree

6 files changed

+35
-57
lines changed

6 files changed

+35
-57
lines changed

homeassistant/components/lifx/binary_sensor.py

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
)
99
from homeassistant.config_entries import ConfigEntry
1010
from homeassistant.const import EntityCategory
11-
from homeassistant.core import HomeAssistant, callback
11+
from homeassistant.core import HomeAssistant
1212
from homeassistant.helpers.entity_platform import AddEntitiesCallback
1313

1414
from .const import DOMAIN, HEV_CYCLE_STATE
@@ -40,6 +40,7 @@ class LIFXHevCycleBinarySensorEntity(LIFXEntity, BinarySensorEntity):
4040
"""LIFX HEV cycle state binary sensor."""
4141

4242
_attr_has_entity_name = True
43+
_attr_should_poll = False
4344

4445
def __init__(
4546
self,
@@ -50,15 +51,8 @@ def __init__(
5051
super().__init__(coordinator)
5152
self.entity_description = description
5253
self._attr_unique_id = f"{coordinator.serial_number}_{description.key}"
53-
self._async_update_attrs()
5454

55-
@callback
56-
def _handle_coordinator_update(self) -> None:
57-
"""Handle updated data from the coordinator."""
58-
self._async_update_attrs()
59-
super()._handle_coordinator_update()
60-
61-
@callback
62-
def _async_update_attrs(self) -> None:
63-
"""Handle coordinator updates."""
64-
self._attr_is_on = self.coordinator.async_get_hev_cycle_state()
55+
@property
56+
def is_on(self) -> bool | None:
57+
"""Returns true if a HEV cycle is currently running."""
58+
return self.coordinator.async_get_hev_cycle_state()

homeassistant/components/lifx/config_flow.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ async def _async_handle_discovery(
9393
host, serial=serial, raise_on_progress=True
9494
)
9595
):
96-
return self.async_abort(reason="cannot_connect") # pragma: no cover
96+
return self.async_abort(reason="cannot_connect")
9797
self._discovered_device = device
9898
return await self.async_step_discovery_confirm()
9999

@@ -172,7 +172,7 @@ async def async_step_pick_device(
172172
device_without_label.ip_addr, raise_on_progress=False
173173
)
174174
if not device:
175-
return self.async_abort(reason="cannot_connect") # pragma: no cover
175+
return self.async_abort(reason="cannot_connect")
176176
return self._async_create_entry_from_device(device)
177177

178178
configured_serials: set[str] = set()
@@ -243,9 +243,8 @@ async def _async_try_connect(
243243
or lifx_features(device)["relays"] is True
244244
or device.host_firmware_version is None
245245
):
246-
return None # relays not supported
247-
# device.mac_addr is not the mac_address, its the serial number
248-
device.mac_addr = serial or messages[0].target_addr
246+
return None
247+
249248
await self.async_set_unique_id(
250249
formatted_serial(device.mac_addr), raise_on_progress=raise_on_progress
251250
)

homeassistant/components/lifx/manager.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
import asyncio
55
from collections.abc import Callable
6-
from datetime import timedelta
76
from typing import Any
87

98
import aiolifx_effects
@@ -33,8 +32,6 @@
3332
from .coordinator import LIFXUpdateCoordinator, Light
3433
from .util import convert_8_to_16, find_hsbk
3534

36-
SCAN_INTERVAL = timedelta(seconds=10)
37-
3835
SERVICE_EFFECT_COLORLOOP = "effect_colorloop"
3936
SERVICE_EFFECT_FLAME = "effect_flame"
4037
SERVICE_EFFECT_MORPH = "effect_morph"

homeassistant/components/lifx/select.py

Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from homeassistant.components.select import SelectEntity, SelectEntityDescription
77
from homeassistant.config_entries import ConfigEntry
88
from homeassistant.const import EntityCategory
9-
from homeassistant.core import HomeAssistant, callback
9+
from homeassistant.core import HomeAssistant
1010
from homeassistant.helpers.entity_platform import AddEntitiesCallback
1111

1212
from .const import (
@@ -59,6 +59,7 @@ class LIFXInfraredBrightnessSelectEntity(LIFXEntity, SelectEntity):
5959
"""LIFX Nightvision infrared brightness configuration entity."""
6060

6161
_attr_has_entity_name = True
62+
_attr_should_poll = False
6263

6364
def __init__(
6465
self,
@@ -71,16 +72,10 @@ def __init__(
7172
self._attr_unique_id = f"{coordinator.serial_number}_{description.key}"
7273
self._attr_current_option = coordinator.current_infrared_brightness
7374

74-
@callback
75-
def _handle_coordinator_update(self) -> None:
76-
"""Handle updated data from the coordinator."""
77-
self._async_update_attrs()
78-
super()._handle_coordinator_update()
79-
80-
@callback
81-
def _async_update_attrs(self) -> None:
82-
"""Handle coordinator updates."""
83-
self._attr_current_option = self.coordinator.current_infrared_brightness
75+
@property
76+
def current_option(self) -> str | None:
77+
"""Return current IR brightness value."""
78+
return self.coordinator.current_infrared_brightness
8479

8580
async def async_select_option(self, option: str) -> None:
8681
"""Update the infrared brightness value."""
@@ -91,6 +86,7 @@ class LIFXThemeSelectEntity(LIFXEntity, SelectEntity):
9186
"""Theme entity for LIFX multizone devices."""
9287

9388
_attr_has_entity_name = True
89+
_attr_should_poll = False
9490

9591
def __init__(
9692
self,
@@ -104,16 +100,10 @@ def __init__(
104100
self._attr_unique_id = f"{coordinator.serial_number}_{description.key}"
105101
self._attr_current_option = None
106102

107-
@callback
108-
def _handle_coordinator_update(self) -> None:
109-
"""Handle updated data from the coordinator."""
110-
self._async_update_attrs()
111-
super()._handle_coordinator_update()
112-
113-
@callback
114-
def _async_update_attrs(self) -> None:
115-
"""Update attrs from coordinator data."""
116-
self._attr_current_option = self.coordinator.last_used_theme
103+
@property
104+
def current_option(self) -> str:
105+
"""Return last applied theme."""
106+
return self.coordinator.last_used_theme
117107

118108
async def async_select_option(self, option: str) -> None:
119109
"""Paint the selected theme onto the device."""

homeassistant/components/lifx/sensor.py

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
"""Sensors for LIFX lights."""
22
from __future__ import annotations
33

4-
from datetime import timedelta
5-
64
from homeassistant.components.sensor import (
75
SensorDeviceClass,
86
SensorEntity,
@@ -18,8 +16,6 @@
1816
from .coordinator import LIFXUpdateCoordinator
1917
from .entity import LIFXEntity
2018

21-
SCAN_INTERVAL = timedelta(seconds=30)
22-
2319
RSSI_SENSOR = SensorEntityDescription(
2420
key=ATTR_RSSI,
2521
name="RSSI",
@@ -42,6 +38,7 @@ class LIFXRssiSensor(LIFXEntity, SensorEntity):
4238
"""LIFX RSSI sensor."""
4339

4440
_attr_has_entity_name = True
41+
_attr_should_poll = False
4542

4643
def __init__(
4744
self,
@@ -55,16 +52,10 @@ def __init__(
5552
self._attr_unique_id = f"{coordinator.serial_number}_{description.key}"
5653
self._attr_native_unit_of_measurement = coordinator.rssi_uom
5754

58-
@callback
59-
def _handle_coordinator_update(self) -> None:
60-
"""Handle updated data from the coordinator."""
61-
self._async_update_attrs()
62-
super()._handle_coordinator_update()
63-
64-
@callback
65-
def _async_update_attrs(self) -> None:
66-
"""Handle coordinator updates."""
67-
self._attr_native_value = self.coordinator.rssi
55+
@property
56+
def native_value(self) -> int:
57+
"""Return last known RSSI value."""
58+
return self.coordinator.rssi
6859

6960
@callback
7061
async def async_added_to_hass(self) -> None:

tests/components/lifx/test_light.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1124,7 +1124,7 @@ async def test_config_zoned_light_strip_fails(hass: HomeAssistant) -> None:
11241124
entity_id = "light.my_bulb"
11251125

11261126
class MockFailingLifxCommand:
1127-
"""Mock a lifx command that fails on the 3rd try."""
1127+
"""Mock a lifx command that fails on the 3rd and 4th try then restores itself."""
11281128

11291129
def __init__(self, bulb, **kwargs):
11301130
"""Init command."""
@@ -1134,7 +1134,10 @@ def __init__(self, bulb, **kwargs):
11341134
def __call__(self, callb=None, *args, **kwargs):
11351135
"""Call command."""
11361136
self.call_count += 1
1137-
response = None if self.call_count >= 3 else MockMessage()
1137+
if 3 <= self.call_count <= 5:
1138+
response = None
1139+
else:
1140+
response = MockMessage()
11381141
if callb:
11391142
callb(self.bulb, response)
11401143

@@ -1151,6 +1154,10 @@ def __call__(self, callb=None, *args, **kwargs):
11511154
await hass.async_block_till_done()
11521155
assert hass.states.get(entity_id).state == STATE_UNAVAILABLE
11531156

1157+
async_fire_time_changed(hass, dt_util.utcnow() + timedelta(seconds=30))
1158+
await hass.async_block_till_done()
1159+
assert hass.states.get(entity_id).state == STATE_OFF
1160+
11541161

11551162
async def test_white_light_fails(hass: HomeAssistant) -> None:
11561163
"""Test we handle failure to power on off."""

0 commit comments

Comments
 (0)
0