Merge pull request #25 from MarjovanLier/fix-multiple-devices

(Fixed) Ensure entities from multiple Owlet devices register correctly
This commit is contained in:
ryanbdclark
2025-04-15 19:08:46 +01:00
committed by GitHub
4 changed files with 14 additions and 10 deletions
+2 -2
View File
@@ -106,11 +106,11 @@ async def async_setup_entry(
sensors = [] sensors = []
for coordinator in coordinators: for coordinator in coordinators:
sensors = [ sensors.extend([
OwletBinarySensor(coordinator, sensor) OwletBinarySensor(coordinator, sensor)
for sensor in SENSORS for sensor in SENSORS
if sensor.key in coordinator.sock.properties if sensor.key in coordinator.sock.properties
] ])
if OwletAwakeSensor.entity_description.key in coordinator.sock.properties: if OwletAwakeSensor.entity_description.key in coordinator.sock.properties:
sensors.append(OwletAwakeSensor(coordinator)) sensors.append(OwletAwakeSensor(coordinator))
+9 -5
View File
@@ -19,6 +19,7 @@ class OwletBaseEntity(CoordinatorEntity[OwletCoordinator], Entity):
) -> None: ) -> None:
"""Initialize the base entity.""" """Initialize the base entity."""
super().__init__(coordinator) super().__init__(coordinator)
self.coordinator = coordinator
self.sock = coordinator.sock self.sock = coordinator.sock
@property @property
@@ -26,9 +27,12 @@ class OwletBaseEntity(CoordinatorEntity[OwletCoordinator], Entity):
"""Return the device info of the device.""" """Return the device info of the device."""
return DeviceInfo( return DeviceInfo(
identifiers={(DOMAIN, self.sock.serial)}, identifiers={(DOMAIN, self.sock.serial)},
name="Owlet Baby Care Sock", name=f"Owlet Sock {self.sock.serial}",
manufacturer=MANUFACTURER, connections={("mac", getattr(self.sock, "mac", "unknown"))},
model=self.sock.model, suggested_area="Nursery",
sw_version=self.sock.sw_version, configuration_url="https://my.owletcare.com/",
hw_version=f"{self.sock.version}r{self.sock.revision}", manufacturer="Owlet Baby Care",
model=getattr(self.sock, "model", None),
sw_version=getattr(self.sock, "sw_version", None),
hw_version=getattr(self.sock, "hw_version", "3r8"),
) )
+2 -2
View File
@@ -115,11 +115,11 @@ async def async_setup_entry(
sensors = [] sensors = []
for coordinator in coordinators: for coordinator in coordinators:
sensors = [ sensors.extend([
OwletSensor(coordinator, sensor) OwletSensor(coordinator, sensor)
for sensor in SENSORS for sensor in SENSORS
if sensor.key in coordinator.sock.properties if sensor.key in coordinator.sock.properties
] ])
if OwletSleepSensor.entity_description.key in coordinator.sock.properties: if OwletSleepSensor.entity_description.key in coordinator.sock.properties:
sensors.append(OwletSleepSensor(coordinator)) sensors.append(OwletSleepSensor(coordinator))
+1 -1
View File
@@ -52,7 +52,7 @@ async def async_setup_entry(
switches = [] switches = []
for coordinator in coordinators: for coordinator in coordinators:
switches = [OwletBaseSwitch(coordinator, switch) for switch in SWITCHES] switches.extend([OwletBaseSwitch(coordinator, switch) for switch in SWITCHES])
async_add_entities(switches) async_add_entities(switches)