Fix Madvr sensor values on startup (#122479)
* fix: add startup values * fix: update snap * fix: use native value to show None
This commit is contained in:
parent
aee1be1e64
commit
392f64d33e
2 changed files with 25 additions and 1 deletions
|
@ -277,4 +277,15 @@ class MadvrSensor(MadVREntity, SensorEntity):
|
||||||
@property
|
@property
|
||||||
def native_value(self) -> float | str | None:
|
def native_value(self) -> float | str | None:
|
||||||
"""Return the state of the sensor."""
|
"""Return the state of the sensor."""
|
||||||
return self.entity_description.value_fn(self.coordinator)
|
val = self.entity_description.value_fn(self.coordinator)
|
||||||
|
# check if sensor is enum
|
||||||
|
if self.entity_description.device_class == SensorDeviceClass.ENUM:
|
||||||
|
if (
|
||||||
|
self.entity_description.options
|
||||||
|
and val in self.entity_description.options
|
||||||
|
):
|
||||||
|
return val
|
||||||
|
# return None for values that are not in the options
|
||||||
|
return None
|
||||||
|
|
||||||
|
return val
|
||||||
|
|
|
@ -93,3 +93,16 @@ async def test_sensor_setup_and_states(
|
||||||
|
|
||||||
# test get_temperature ValueError
|
# test get_temperature ValueError
|
||||||
assert get_temperature(None, "temp_key") is None
|
assert get_temperature(None, "temp_key") is None
|
||||||
|
|
||||||
|
# test startup placeholder values
|
||||||
|
update_callback({"outgoing_bit_depth": "0bit"})
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
assert (
|
||||||
|
hass.states.get("sensor.madvr_envy_outgoing_bit_depth").state == STATE_UNKNOWN
|
||||||
|
)
|
||||||
|
|
||||||
|
update_callback({"outgoing_color_space": "?"})
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
assert (
|
||||||
|
hass.states.get("sensor.madvr_envy_outgoing_color_space").state == STATE_UNKNOWN
|
||||||
|
)
|
||||||
|
|
Loading…
Add table
Reference in a new issue