Skip to content

Commit

Permalink
I *think* this will fix #10 . Not 100% sure the timestamps are sane. …
Browse files Browse the repository at this point in the history
…Requires testing.

Will verify it at least runs on my system later..
  • Loading branch information
garbled1 committed Nov 12, 2020
1 parent 508160e commit 81641f2
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
15 changes: 15 additions & 0 deletions custom_components/ecowitt/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
PRESSURE_HPA,
PRESSURE_INHG,
LENGTH_INCHES,
LENGTH_KILOMETERS,
LENGTH_MILES,
SPEED_KILOMETERS_PER_HOUR,
SPEED_MILES_PER_HOUR,
TIME_HOURS,
Expand All @@ -45,6 +47,7 @@
DEVICE_CLASS_ILLUMINANCE,
DEVICE_CLASS_TEMPERATURE,
DEVICE_CLASS_PRESSURE,
DEVICE_CLASS_TIMESTAMP,
)

_LOGGER = logging.getLogger(__name__)
Expand Down Expand Up @@ -144,6 +147,10 @@
TYPE_PM25_AVG_24H_CH2 = "pm25_avg_24h_ch2"
TYPE_PM25_AVG_24H_CH3 = "pm25_avg_24h_ch3"
TYPE_PM25_AVG_24H_CH4 = "pm25_avg_24h_ch4"
TYPE_LIGHTNING_TIME = "lightning_time"
TYPE_LIGHTNING_NUM = "lightning_num"
TYPE_LIGHTNING_KM = "lightning"
TYPE_LIGHTNING_MI = "lightning_mi"
TYPE_WH68BATT = "wh68batt"
TYPE_WH40BATT = "wh40batt"
TYPE_WH26BATT = "wh26batt"
Expand Down Expand Up @@ -384,6 +391,14 @@
TYPE_PM25_AVG_24H_CH4: ("PM2.5 24h average 4",
CONCENTRATION_MICROGRAMS_PER_CUBIC_METER,
TYPE_SENSOR, None, "mdi:eye", 0),
TYPE_LIGHTNING_TIME: ("Last Lightning strike", "",
TYPE_SENSOR, DEVICE_CLASS_TIMESTAMP, "mdi:clock", 0),
TYPE_LIGHTNING_NUM: ("Lightning strikes", f"strikes/{TIME_DAYS}",
TYPE_SENSOR, None, "mdi:weather-lightning", 0),
TYPE_LIGHTNING_KM: ("Lightning strike distance", LENGTH_KILOMETERS,
TYPE_SENSOR, None, "mdi:ruler", S_METRIC),
TYPE_LIGHTNING_MI: ("Lightning strike distance", LENGTH_MILES,
TYPE_SENSOR, None, "mdi:ruler", S_IMPERIAL),
TYPE_WH68BATT: ("WH68 Battery", "BATT", TYPE_SENSOR,
None, "mdi:battery", 0),
TYPE_WH40BATT: ("WH40 Battery", "BATT", TYPE_SENSOR,
Expand Down
7 changes: 7 additions & 0 deletions custom_components/ecowitt/sensor.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
"""Support for Ecowitt Weather Stations."""
import logging
import homeassistant.util.dt as dt_util

from . import (
TYPE_SENSOR,
DOMAIN,
DATA_STATION,
SENSOR_TYPES,
EcowittEntity,
DEVICE_CLASS_TIMESTAMP
)

from homeassistant.const import STATE_UNKNOWN
Expand Down Expand Up @@ -51,6 +53,11 @@ def __init__(self, hass, key, name, dc, uom, icon):
def state(self):
"""Return the state of the sensor."""
if self._key in self._ws.last_values:
# Im concerned this is nonsense due to TZ...
if self._dc == DEVICE_CLASS_TIMESTAMP:
return dt_util.as_local(
dt_util.utc_from_timestamp(self._ws.last_values[self._key])
).isoformat()
return self._ws.last_values[self._key]
_LOGGER.warning("Sensor %s not in last update, check range or battery",
self._key)
Expand Down

0 comments on commit 81641f2

Please sign in to comment.