1 """Support for monitoring a Sense energy sensor device."""
5 from sense_energy.sense_api
import SenseDevice
8 BinarySensorDeviceClass,
15 from .
import SenseConfigEntry
16 from .const
import DOMAIN
17 from .coordinator
import SenseRealtimeCoordinator
18 from .entity
import SenseDeviceEntity
20 _LOGGER = logging.getLogger(__name__)
25 config_entry: SenseConfigEntry,
26 async_add_entities: AddEntitiesCallback,
28 """Set up the Sense binary sensor."""
29 sense_monitor_id = config_entry.runtime_data.data.sense_monitor_id
30 realtime_coordinator = config_entry.runtime_data.rt
34 for device
in config_entry.runtime_data.data.devices
43 """Implementation of a Sense energy device binary sensor."""
45 _attr_device_class = BinarySensorDeviceClass.POWER
50 coordinator: SenseRealtimeCoordinator,
51 sense_monitor_id: str,
53 """Initialize the Sense binary sensor."""
54 super().
__init__(device, coordinator, sense_monitor_id, device.id)
55 self.
_id_id = device.id
59 """Return the old not so unique id of the binary sensor."""
64 """Return the state of the sensor."""
65 return self.
_device_device.is_on
69 hass: HomeAssistant, devices: list[SenseBinarySensor]
71 registry = er.async_get(hass)
72 for device
in devices:
74 old_entity_id = registry.async_get_entity_id(
75 "binary_sensor", DOMAIN, device.old_unique_id
77 updated_id = device.unique_id
78 if old_entity_id
is not None and updated_id
is not None:
80 "Migrating unique_id from [%s] to [%s]",
84 registry.async_update_entity(old_entity_id, new_unique_id=updated_id)
None __init__(self, SenseDevice device, SenseRealtimeCoordinator coordinator, str sense_monitor_id)
None async_setup_entry(HomeAssistant hass, SenseConfigEntry config_entry, AddEntitiesCallback async_add_entities)
None _migrate_old_unique_ids(HomeAssistant hass, list[SenseBinarySensor] devices)