Skip to content

Commit

Permalink
Fix #144 Sensor component's "unavailable" value should return None
Browse files Browse the repository at this point in the history
  • Loading branch information
nao-pon committed Oct 4, 2023
1 parent ddc9763 commit bb0c2a7
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions custom_components/echonetlite/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
ENERGY_WATT_HOUR,
VOLUME_CUBIC_METERS,
ELECTRIC_CURRENT_AMPERE,
STATE_UNAVAILABLE,
DEVICE_CLASS_GAS,
DEVICE_CLASS_VOLTAGE,
ELECTRIC_POTENTIAL_VOLT,
Expand Down Expand Up @@ -394,16 +393,16 @@ def native_value(self) -> StateType:
* self._connector._update_data[0xE1]
) # value in kWh
else:
return STATE_UNAVAILABLE
return None

if self._state_value is None:
return STATE_UNAVAILABLE
return None
elif self._sensor_attributes[CONF_TYPE] in [
DEVICE_CLASS_TEMPERATURE,
DEVICE_CLASS_HUMIDITY,
]:
if self._state_value in [126, 253]:
return STATE_UNAVAILABLE
return None
else:
return self._state_value
elif self._sensor_attributes[CONF_TYPE] == DEVICE_CLASS_POWER:
Expand All @@ -418,8 +417,8 @@ def native_value(self) -> StateType:
if len(self._state_value) < 255:
return self._state_value
else:
return STATE_UNAVAILABLE
return STATE_UNAVAILABLE
return None
return None

@property
def native_unit_of_measurement(self):
Expand Down

0 comments on commit bb0c2a7

Please sign in to comment.