litinoveweedle / SmartIR

⏻ Control Home Assistant climate, media and fan devices via IR/RF controllers (Broadlink, Xiaomi, MQTT, LOOKin, ESPHome)
MIT License
45 stars 12 forks source link

Exception in callback _run_async_call_action #32

Closed CFFAA closed 3 weeks ago

CFFAA commented 3 weeks ago

Hi Recently installed version 1.17.15 Currently Running HA 2024.6.1

Devices working fine (all are UFO R11) but there are some errors in logs:

Logger: homeassistant Source: custom_components/smartir/climate.py:725 integration: smartir (documentation, issues) First occurred: 09:52:06 (3 occurrences) Last logged: 09:52:06

Traceback (most recent call last): File "/usr/local/lib/python3.12/asyncio/events.py", line 88, in _run self._context.run(self._callback, *self._args) File "/usr/src/homeassistant/homeassistant/helpers/event.py", line 1510, in _run_async_call_action hass.async_run_hass_job(job, time_tracker_utcnow()) File "/usr/src/homeassistant/homeassistant/core.py", line 936, in async_run_hass_job hassjob.target(*args) File "/config/custom_components/smartir/climate.py", line 725, in _async_power_sensor_check current_state = self.hass.states.get(self._power_sensor).state ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ AttributeError: 'NoneType' object has no attribute 'state'

litinoveweedle commented 3 weeks ago

You are not making it easy for me. No config, no debug logs. Obvious question, do you use power sensor functionality? Is is correctly named? Does it work? Check in HA what is the state of the power sensor entity.

CFFAA commented 3 weeks ago

Thanks for answer sorry about the lack of more context. Yes Im using the power sensor feature. All the power sensor entities works in HA

Maybe some of the power sensors I use are not available when HA recently started?

Got one climate entity configured for a broadlink:

And same AC controlled by the UFO-R11 using MQTT with a custom_climate file

And another AC controlled only with UFO-R11 with the same custom_climate file:

litinoveweedle commented 3 weeks ago

the problem is, that HA returned back to the SmartIR integration, that state object of the power sensor is 'None'. I can fix easily that this will not throw exceptions, but the problem is, that this should not happen. And we do not know the reason why it is happening.

Could you please try to reproduce the issue with:

CFFAA commented 3 weeks ago

Thanks for taking your time after adding the lines you suggested here is the results from the log:

2024-06-12 14:55:38.317 DEBUG (MainThread) [custom_components.smartir.climate] Setting up the SmartIR climate platform 2024-06-12 14:55:38.321 DEBUG (MainThread) [custom_components.smartir.climate] Setting up the SmartIR climate platform 2024-06-12 14:55:38.323 DEBUG (MainThread) [custom_components.smartir.climate] Setting up the SmartIR climate platform 2024-06-12 14:55:38.378 DEBUG (MainThread) [custom_components.smartir.climate] SmartIRClimate init started for device Salon AC LG supported models ['P12RK'] 2024-06-12 14:55:38.380 DEBUG (MainThread) [custom_components.smartir.climate] async_added_to_hass Salon AC LG 393 2024-06-12 14:55:38.380 DEBUG (MainThread) [custom_components.smartir.climate] Scheduled power sensor check for 'off' state 2024-06-12 14:55:38.403 DEBUG (MainThread) [custom_components.smartir.climate] SmartIRClimate init started for device Salon AC LG MOES supported models ['E12EM'] 2024-06-12 14:55:38.403 WARNING (MainThread) [custom_components.smartir.climate] Device data file is missing 'temperatureUnit' key, using 'C' as default. 2024-06-12 14:55:38.406 DEBUG (MainThread) [custom_components.smartir.climate] async_added_to_hass Salon AC LG MOES 393 2024-06-12 14:55:38.406 DEBUG (MainThread) [custom_components.smartir.climate] Scheduled power sensor check for 'off' state 2024-06-12 14:55:38.408 DEBUG (MainThread) [custom_components.smartir.climate] SmartIRClimate init started for device Dormitorio AC LG MOES supported models ['E12EM'] 2024-06-12 14:55:38.408 WARNING (MainThread) [custom_components.smartir.climate] Device data file is missing 'temperatureUnit' key, using 'C' as default. 2024-06-12 14:55:38.409 DEBUG (MainThread) [custom_components.smartir.climate] async_added_to_hass Dormitorio AC LG MOES 393 2024-06-12 14:55:38.410 DEBUG (MainThread) [custom_components.smartir.climate] Scheduled power sensor check for 'off' state

All the binary_sensors to manage the power sensor entity are off according to dev tools

litinoveweedle commented 3 weeks ago

Thank you, but I need the debug log after the exception appears... This seems to be only after startup.

CFFAA commented 3 weeks ago

I made again some tests deleting the part of the power sensor entity and with that no more errors are printed in the log, so I assume that the binary sensors are not ready yet when the component requires. As I said after HA started completely the smartIR entities worked as expected

litinoveweedle commented 3 weeks ago

Thank you for help. I now probably understand, what is going on. When SmartIR entity is registered to HA, it schedule run of the power sensor check routine in (by default) 10seconds.

Unfortunately this is not very scientific approach in some cases it can take longer for HA to register power sensor entity. And if after 10second entity is not registered the HA return None instead of expected state object. So I need to find best way how to schedule initial power sensor check (or check if it is really necessary...).

litinoveweedle commented 3 weeks ago

Ok, can you please edit climate.py a replace somewhere around line 723:

current_state = self.hass.states.get(self._power_sensor).state

by

current_state = getattr(self.hass.states.get(self._power_sensor), 'state', None)

you can also delete line around 263:

self._async_power_sensor_check_schedule(self._state)

Please restart HA and recheck, it should solve the issue. ;-)

CFFAA commented 3 weeks ago

After those changes no more Errors are shown in the log. Also the power sensor options worked as expected! thank you

litinoveweedle commented 3 weeks ago

Cool, thank you for testing. I will inherit proposed changes into new release ASAP.

litinoveweedle commented 3 weeks ago

Fixed in release 1.17.16, closing issue now.