Skip to content

Commit

Permalink
Add unit_of_measurement and device_class from the input sensor
Browse files Browse the repository at this point in the history
  • Loading branch information
woopstar committed Sep 29, 2024
1 parent f1a838a commit 0723940
Showing 1 changed file with 15 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ def __init__(
self._last_update_time = None
self._last_updated = None
self._update_interval = update_interval
self._unit_of_measurement = None
self._device_class = None
self._unique_id = f"sas_lowpass_{sensor_hash}"

@property
Expand All @@ -49,6 +51,14 @@ def unique_id(self):
def state(self):
return self._state

@property
def unit_of_measurement(self):
return self._unit_of_measurement

@property
def device_class(self):
return self._device_class

@property
def device_info(self):
"""Return device information for the Lowpass Sensor."""
Expand Down Expand Up @@ -100,10 +110,15 @@ async def async_update(self):
except ValueError:
return

# Fetch unit_of_measurement and device_class from the input sensor
self._unit_of_measurement = input_state.attributes.get("unit_of_measurement")
self._device_class = input_state.attributes.get("device_class")

# Apply lowpass filter
self._state = round(
lowpass_filter(current_value, self._previous_value, self._time_constant), 2
)

self._previous_value = current_value
self._last_updated = now.isoformat()

Expand Down

0 comments on commit 0723940

Please sign in to comment.