Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
DoerakkerHA opened this issue Jul 6, 2022 · 5 comments

Comments

@DoerakkerHA
Copy link

DoerakkerHA commented Jul 6, 2022

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
Copy link
Author

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
Copy link
Author

DoerakkerHA commented Jul 12, 2022

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 DEVICE_CLASS_* constants deprecated
The use of the DEVICE_CLASS_* 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
Copy link

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

@DoerakkerHA
Copy link
Author

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
Copy link
Author

Ok., have uninstalled this version completely and using the official supported integration home-assistant/core#77441

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants