mirror of
https://github.com/home-assistant/core.git
synced 2025-04-25 09:47:52 +00:00
lacrosse_view: Set entity availablity depending on the data (#85303)
This commit is contained in:
parent
3ecbb235cc
commit
aace1da358
@ -48,9 +48,6 @@ def get_value(sensor: Sensor, field: str) -> float | int | str | None:
|
||||
"""Get the value of a sensor field."""
|
||||
field_data = sensor.data.get(field)
|
||||
if field_data is None:
|
||||
LOGGER.warning(
|
||||
"No field %s in response for %s (%s)", field, sensor.name, sensor.model
|
||||
)
|
||||
return None
|
||||
value = field_data["values"][-1]["s"]
|
||||
try:
|
||||
@ -196,3 +193,11 @@ class LaCrosseViewSensor(
|
||||
return self.entity_description.value_fn(
|
||||
self.coordinator.data[self.index], self.entity_description.key
|
||||
)
|
||||
|
||||
@property
|
||||
def available(self) -> bool:
|
||||
"""Return True if entity is available."""
|
||||
return (
|
||||
super().available
|
||||
and self.entity_description.key in self.coordinator.data[self.index].data
|
||||
)
|
||||
|
@ -130,5 +130,4 @@ async def test_no_field(hass: HomeAssistant, caplog: Any) -> None:
|
||||
assert entries
|
||||
assert len(entries) == 1
|
||||
assert entries[0].state == ConfigEntryState.LOADED
|
||||
assert hass.states.get("sensor.test_temperature").state == "unknown"
|
||||
assert "No field Temperature in response for Test (Test)" in caplog.text
|
||||
assert hass.states.get("sensor.test_temperature").state == "unavailable"
|
||||
|
Loading…
x
Reference in New Issue
Block a user