garbled1 / homeassistant_ecowitt

Ecowitt Weather Station integration for homeassistant
Apache License 2.0
143 stars 70 forks source link

Error while setting up ecowitt platform for sensor WH57 Lightning Detection #128

Closed DoerakkerHA closed 2 years ago

DoerakkerHA commented 2 years ago

See also Issue #112 slightly different log

Recently added WH57 Lightning Detection sensor Data shows in app & ecowitt environment (sensor is cretead and no error messages displayed) Sensor values are transmited from the HACS addon except last lightning:

Logger: homeassistant.components.sensor Source: components/sensor/init.py:408 Integration: Sensor (documentation, issues) First occurred: 11:23:52 (2 occurrences) Last logged: 11:23:52

Error adding entities for domain sensor with platform ecowitt Error while setting up ecowitt platform for sensor Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/components/sensor/init.py", line 397, in state if value.tzinfo is None: AttributeError: 'str' object has no attribute 'tzinfo'

The above exception was the direct cause of the following exception:

Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 382, in async_add_entities await asyncio.gather(*tasks) File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 619, in _async_add_entity await entity.add_to_platform_finish() File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 810, in add_to_platform_finish self.async_write_ha_state() File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 533, in async_write_ha_state self._async_write_ha_state() File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 571, in _async_write_ha_state state = self._stringify_state(available) File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 539, in _stringify_state if (state := self.state) is None: File "/usr/src/homeassistant/homeassistant/components/sensor/init.py", line 408, in state raise ValueError( ValueError: Invalid datetime: sensor.last_lightning_strike has a timestamp device class but does not provide a datetime state but <class 'str'>

DoerakkerHA commented 2 years ago

I am not a programmer .... and tried the following to reduce the number of errors in the log:

file: const.py line 500-503 was: TYPE_LIGHTNING_TIME: ("Last Lightning strike", "", TYPE_SENSOR, DEVICE_CLASS_TIMESTAMP, "mdi:clock", 0, STATE_CLASS_MEASUREMENT), file: const.py line 500-503 is: TYPE_LIGHTNING_TIME: ("Last Lightning strike", "", TYPE_SENSOR, None, "mdi:clock", 0, STATE_CLASS_MEASUREMENT),

result: no more errors after reboot HASSIO ... not sure what else I might have ... up ;-) as we are not in heavy lightning area I cannot conform the actual operation by above change.

DoerakkerHA commented 2 years ago

UPDATE: I have just tested the change in my production environment. Using a piezo lighter near the sensor .... drumroll

In the ecowitt app it shows: Last Distance: 16KM Last Timestamp: 07/12/2022 12:00 Daily Count: 2

The value stored in this sensor is (epoch) 1657620032

Now as I am unfamilliar with Github how can I get this into the official code? Or are there other suggestions / improvements

it turns out this is broken due to HA21 DEVICECLASS constants deprecated The use of the DEVICECLASS constants and DEVICE_CLASSES constants in all entity platforms, has now been depreacted. Instead, use the equavalent DeviceClass StrEnum provided by each platform.

james-pinckney commented 2 years ago

I think this will be corrected by the PR I just submitted... https://github.com/garbled1/homeassistant_ecowitt/pull/131

DoerakkerHA commented 2 years ago

I think this will be corrected by the PR I just submitted... #131

what is the status of this PR ? I have downloaded, installed and tested the new files, what can I do to get this moved along to a new release?

DoerakkerHA commented 2 years ago

Ok., have uninstalled this version completely and using the official supported integration https://github.com/home-assistant/core/pull/77441