Skip to content

Commit

Permalink
#16 - First pass at last updated time value
Browse files Browse the repository at this point in the history
  • Loading branch information
muppet3000 committed Jul 4, 2023
1 parent 4fd077a commit 759caf0
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion custom_components/grott/sensors/sensors_mqtt.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
"""Sensor descriptions for Growatt systems - Raw MQTT values."""

from __future__ import annotations

import datetime

from homeassistant.components.sensor import SensorDeviceClass, SensorStateClass
from homeassistant.const import (
PERCENTAGE,
Expand All @@ -13,6 +15,7 @@
UnitOfTime,
)
from homeassistant.helpers.entity import DeviceInfo, EntityCategory
from homeassistant.util import dt

from ..const import (
BATTERY_TYPES
Expand All @@ -24,6 +27,11 @@ def battery_type_lookup(mqtt_data):
batt_type = 2
return BATTERY_TYPES[int(batt_type)]

def datetime_formatter(mqtt_data):
last_updated_time_string = mqtt_data['time']
last_updated_date_time = dt.parse_datetime(last_updated_time_string)
return datetime.datetime.combine(last_updated_date_time.date(), last_updated_date_time.time(), dt.DEFAULT_TIME_ZONE)

SENSORS_LABEL="raw_mqtt_sensors"

SENSORS = [
Expand Down Expand Up @@ -1074,6 +1082,18 @@ def battery_type_lookup(mqtt_data):
"unique_name": "mqtt_098",
},

{
"name": "Last data update",
"device_class": SensorDeviceClass.TIMESTAMP,
"unit_of_measurement": None,
"state_class": None,
"entity_category": EntityCategory.DIAGNOSTIC,
"icon": "mdi:information-outline",
"func": datetime_formatter,
"unique_name": "mqtt_099",
},


#The following entries are out-of-order in the above list, be sure to check for the latest value for unique_name from both lists
#mqtt_066 - PV3 Voltage
#mqtt_067 - PV3 Current
Expand Down

0 comments on commit 759caf0

Please sign in to comment.