Skip to content

Commit

Permalink
handle power sensors not available Powertag-E no attribute "get" (new…
Browse files Browse the repository at this point in the history
… on 3.4.4) #449
  • Loading branch information
msp1974 committed Mar 5, 2024
1 parent 6960ccc commit 7649414
Showing 1 changed file with 26 additions and 15 deletions.
41 changes: 26 additions & 15 deletions custom_components/wiser/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -1193,25 +1193,36 @@ def _handle_coordinator_update(self) -> None:
"""Fetch new state data for the sensor."""
super()._handle_coordinator_update()
if self._lts_sensor_type == "Power":
self._state = self._data.wiserhub.devices.get_by_id(self._device_id).get(
"instantaneous_power", 0
)
if self._data.wiserhub.devices.get_by_id(
self._device_id
).instantaneous_power:
self._state = self._data.wiserhub.devices.get_by_id(
self._device_id
).instantaneous_power
else:
self._state = 0
elif self._lts_sensor_type == "Energy":
self._state = round(
self._data.wiserhub.devices.get_by_id(self._device_id).get(
"delivered_power", 0
if self._data.wiserhub.devices.get_by_id(self._device_id).delivered_power:
self._state = round(
self._data.wiserhub.devices.get_by_id(
self._device_id
).delivered_power
/ 1000,
2,
)
/ 1000,
2,
)
else:
self._state = 0
elif self._lts_sensor_type == "EnergyReceived":
self._state = round(
self._data.wiserhub.devices.get_by_id(self._device_id).get(
"received_power", 0
if self._data.wiserhub.devices.get_by_id(self._device_id).received_power:
self._state = round(
self._data.wiserhub.devices.get_by_id(
self._device_id
).received_power
/ 1000,
2,
)
/ 1000,
2,
)
else:
self._state = 0
self.async_write_ha_state()

@property
Expand Down

0 comments on commit 7649414

Please sign in to comment.