mirror of
https://github.com/home-assistant/core.git
synced 2026-09-05 02:25:07 -05:00
Code optimization for Uptime Robot (#153031)
This commit is contained in:
@@ -37,11 +37,12 @@ async def async_setup_entry(
|
||||
known_devices: set[int] = set()
|
||||
|
||||
def _check_device() -> None:
|
||||
current_devices = {monitor.id for monitor in coordinator.data}
|
||||
new_devices = current_devices - known_devices
|
||||
if new_devices:
|
||||
known_devices.update(new_devices)
|
||||
async_add_entities(
|
||||
entities: list[UptimeRobotSensor] = []
|
||||
for monitor in coordinator.data:
|
||||
if monitor.id in known_devices:
|
||||
continue
|
||||
known_devices.add(monitor.id)
|
||||
entities.append(
|
||||
UptimeRobotSensor(
|
||||
coordinator,
|
||||
SensorEntityDescription(
|
||||
@@ -59,9 +60,9 @@ async def async_setup_entry(
|
||||
),
|
||||
monitor=monitor,
|
||||
)
|
||||
for monitor in coordinator.data
|
||||
if monitor.id in new_devices
|
||||
)
|
||||
if entities:
|
||||
async_add_entities(entities)
|
||||
|
||||
_check_device()
|
||||
entry.async_on_unload(coordinator.async_add_listener(_check_device))
|
||||
|
||||
@@ -34,11 +34,12 @@ async def async_setup_entry(
|
||||
known_devices: set[int] = set()
|
||||
|
||||
def _check_device() -> None:
|
||||
current_devices = {monitor.id for monitor in coordinator.data}
|
||||
new_devices = current_devices - known_devices
|
||||
if new_devices:
|
||||
known_devices.update(new_devices)
|
||||
async_add_entities(
|
||||
entities: list[UptimeRobotSwitch] = []
|
||||
for monitor in coordinator.data:
|
||||
if monitor.id in known_devices:
|
||||
continue
|
||||
known_devices.add(monitor.id)
|
||||
entities.append(
|
||||
UptimeRobotSwitch(
|
||||
coordinator,
|
||||
SwitchEntityDescription(
|
||||
@@ -47,9 +48,9 @@ async def async_setup_entry(
|
||||
),
|
||||
monitor=monitor,
|
||||
)
|
||||
for monitor in coordinator.data
|
||||
if monitor.id in new_devices
|
||||
)
|
||||
if entities:
|
||||
async_add_entities(entities)
|
||||
|
||||
_check_device()
|
||||
entry.async_on_unload(coordinator.async_add_listener(_check_device))
|
||||
|
||||
Reference in New Issue
Block a user