Fix Enphase dry contact binary sensor state updates (#98225)

Fix dry contact binary sensor state updates
This commit is contained in:
Charles Garwood 2023-08-10 18:00:54 -04:00 committed by GitHub
parent 86f94662eb
commit b653d7f683
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -212,15 +212,15 @@ class EnvoyRelayBinarySensorEntity(EnvoyBaseBinarySensorEntity):
self, self,
coordinator: EnphaseUpdateCoordinator, coordinator: EnphaseUpdateCoordinator,
description: BinarySensorEntityDescription, description: BinarySensorEntityDescription,
relay: str, relay_id: str,
) -> None: ) -> None:
"""Init the Enpower base entity.""" """Init the Enpower base entity."""
super().__init__(coordinator, description) super().__init__(coordinator, description)
enpower = self.data.enpower enpower = self.data.enpower
assert enpower is not None assert enpower is not None
self.relay = self.data.dry_contact_status[relay] self.relay_id = relay_id
self._serial_number = enpower.serial_number self._serial_number = enpower.serial_number
self._attr_unique_id = f"{self._serial_number}_relay_{self.relay.id}" self._attr_unique_id = f"{self._serial_number}_relay_{relay_id}"
self._attr_device_info = DeviceInfo( self._attr_device_info = DeviceInfo(
identifiers={(DOMAIN, self._serial_number)}, identifiers={(DOMAIN, self._serial_number)},
manufacturer="Enphase", manufacturer="Enphase",
@ -229,11 +229,10 @@ class EnvoyRelayBinarySensorEntity(EnvoyBaseBinarySensorEntity):
sw_version=str(enpower.firmware_version), sw_version=str(enpower.firmware_version),
via_device=(DOMAIN, self.envoy_serial_num), via_device=(DOMAIN, self.envoy_serial_num),
) )
self._attr_name = ( self._attr_name = f"{self.data.dry_contact_settings[relay_id].load_name} Relay"
f"{self.data.dry_contact_settings[self.relay.id].load_name} Relay"
)
@property @property
def is_on(self) -> bool: def is_on(self) -> bool:
"""Return the state of the Enpower binary_sensor.""" """Return the state of the Enpower binary_sensor."""
return self.relay.status == DryContactStatus.CLOSED relay = self.data.dry_contact_status[self.relay_id]
return relay.status == DryContactStatus.CLOSED