Skip to content

Commit

Permalink
Improve last_update
Browse files Browse the repository at this point in the history
  • Loading branch information
astrandb committed Nov 30, 2024
1 parent c32f7f4 commit 278d429
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 4 deletions.
4 changes: 2 additions & 2 deletions custom_components/weatherlink/binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ def is_on(self):
)
dt_now = dt_util.now()
diff = dt_now - dt_update
return (diff.total_seconds()) / 60 < DISCONNECTED_AFTER_SECONDS
return diff.total_seconds() < DISCONNECTED_AFTER_SECONDS
return None

@property
Expand Down Expand Up @@ -306,6 +306,6 @@ def available(self):
)
dt_now = dt_util.now()
diff = dt_now - dt_update
return (diff.total_seconds()) / 60 < UNAVAILABLE_AFTER_SECONDS
return diff.total_seconds() < UNAVAILABLE_AFTER_SECONDS

return True
23 changes: 21 additions & 2 deletions custom_components/weatherlink/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -584,6 +584,14 @@ class WLSensorDescription(SensorEntityDescription):
exclude_data_structure=(2, 10, 12, 25),
aux_sensors=(323, 326),
),
WLSensorDescription(
key="LastUpdate",
translation_key="last_update",
tag=DataKey.TIMESTAMP,
entity_category=EntityCategory.DIAGNOSTIC,
device_class=SensorDeviceClass.TIMESTAMP,
aux_sensors=(323, 326),
),
)


Expand Down Expand Up @@ -784,7 +792,12 @@ def generate_model(self):
def native_value(self):
"""Return the state of the sensor."""
# _LOGGER.debug("Key: %s", self.entity_description.key)
if self.entity_description.key not in ["WindDir", "BarTrend", "WindGust"]:
if self.entity_description.key not in [
"LastUpdate",
"WindDir",
"BarTrend",
"WindGust",
]:
return self.coordinator.data[self.tx_id].get(self.entity_description.tag)

if self.entity_description.tag in [DataKey.WIND_GUST_MPH]:
Expand Down Expand Up @@ -863,6 +876,12 @@ def native_value(self):
return "falling_slowly"
return "falling_rapidly"
return str(bar_trend).lower().replace(" ", "_")

if self.entity_description.key == "LastUpdate":
return dt_util.utc_from_timestamp(
self.coordinator.data[self.tx_id].get(DataKey.TIMESTAMP)
)

return None

def is_float(self, in_string):
Expand Down Expand Up @@ -924,4 +943,4 @@ def available(self):
)
dt_now = dt_util.now()
diff = dt_now - dt_update
return (diff.total_seconds()) / 60 < UNAVAILABLE_AFTER_SECONDS
return diff.total_seconds() < UNAVAILABLE_AFTER_SECONDS
3 changes: 3 additions & 0 deletions custom_components/weatherlink/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,9 @@
"inside_temperature": {
"name": "Inside temperature"
},
"last_update": {
"name": "Last updated"
},
"moist_soil_1": {
"name": "Soil moisture 1"
},
Expand Down

0 comments on commit 278d429

Please sign in to comment.