Skip to content
This repository has been archived by the owner on Apr 30, 2022. It is now read-only.

Commit

Permalink
Determine sensor availability at runtime
Browse files Browse the repository at this point in the history
attempts to fix #46
  • Loading branch information
unlobito committed Dec 21, 2021
1 parent e0ad1fe commit 1ca3602
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion custom_components/hildebrandglow/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
SensorEntityDescription(
key="gas_consumption",
name="Gas Consumption",
entity_registry_enabled_default=False,
native_unit_of_measurement=VOLUME_CUBIC_METERS,
device_class=DEVICE_CLASS_GAS,
state_class=STATE_CLASS_TOTAL_INCREASING,
Expand Down Expand Up @@ -100,6 +99,11 @@ def on_message(self, message: Any) -> None:
"""Receive callback for incoming MQTT payloads."""
self.hass.add_job(self.async_write_ha_state)

@property
def available(self) -> bool:
"""Return the sensor's availability."""
return getattr(self.glow.data, self.entity_description.key) is not None

@property
def native_value(self) -> StateType:
"""Return the state of the sensor."""
Expand Down

0 comments on commit 1ca3602

Please sign in to comment.