JoDehli / PyLoxone

Python Loxone binding
Apache License 2.0
162 stars 40 forks source link

fixed property "name" on LoxoneCustomerSensor #268

Closed jluthiger closed 1 week ago

jluthiger commented 2 weeks ago

Version 0.6.7 does not work. I have realized that I have not inserted my fixes properly into my master branch. Here follows the rest. Sorry!

This one is tested against home assistant core 2024.5.0 (and 2024.6.0.dev0).

JoDehli commented 2 weeks ago

@jluthiger what error do you get? The name property is already given in the base class and is not needed in the custom sensor class.

jluthiger commented 2 weeks ago

This is the error:

2024-05-05 12:45:23.240 ERROR (MainThread) [homeassistant.components.sensor] Error while setting up loxone platform for sensor
Traceback (most recent call last):
  File "/Users/juerg.luthiger/projects-dev/home-assistant/core/homeassistant/helpers/entity_platform.py", line 356, in _async_setup_platform
    await asyncio.shield(awaitable)
  File "/Users/juerg.luthiger/projects-dev/home-assistant/core/config/custom_components/loxone/sensor.py", line 151, in async_setup_platform
    new_sensor = LoxoneCustomSensor(**config)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/juerg.luthiger/projects-dev/home-assistant/core/config/custom_components/loxone/sensor.py", line 192, in __init__
    super().__init__(**kwargs)
  File "/Users/juerg.luthiger/projects-dev/home-assistant/core/config/custom_components/loxone/__init__.py", line 424, in __init__
    setattr(self, key, kwargs[key])
AttributeError: property 'device_class' of 'LoxoneCustomSensor' object has no setter

But the property device_class is only the first entry of my configuration which is like the following example:

sensor:
  - platform: loxone
    name: EnergyProducerActual
    uuidAction: "1747c962-0201-9514-ffffef235c289060"
    device_class: "power"
    unit_of_measurement: "kW"
    state_class: "measurement"

The same error would I expect for unit_of_measurement and state_class.

jluthiger commented 2 weeks ago

Comment to the background tasks fix. HA complains on startup with:

2024-05-05 14:16:51.244 WARNING (MainThread) [homeassistant.core] Something is blocking Home Assistant from wrapping up the start up phase. We're going to continue anyway. Please report the following info at https://github.com/home-assistant/core/issues: default_config, api, number, switch, loxone.sensor, media_player, cloud, shopping_list, history, counter, update, homeassistant_alerts, network, webhook, loxone.fan, image_upload, my, backup, met.weather, hardware, loxone.switch, notify, automation, loxone.cover, climate, usb, zeroconf, logger, system_health, loxone.media_player, scene, hacs.update, repairs, diagnostics, input_button, conversation, radio_browser, homeassistant.scene, input_boolean, energy.sensor, cover, recorder, google_translate.tts, mobile_app.notify, blueprint, config, input_text, alarm_control_panel, binary_sensor, loxone.light, met, lovelace, hacs.sensor, dhcp, trace, application_credentials, tts, hacs, file_upload, media_source, loxone.number, loxone.binary_sensor, tag, input_datetime, frontend, input_select, input_number, light, loxone, websocket_api, ssdp, schedule, energy, timer, bluetooth, auth, todo, shopping_list.todo, mobile_app, person, analytics, sun.sensor, loxone.scene, sensor, script, weather, device_automation, wake_word, http, sun, map, homeassistant, persistent_notification, system_log, intent, fan, google_translate, zone, ffmpeg, stt, logbook, onboarding, stream, search, loxone.climate, loxone.alarm_control_panel, cloud.tts, assist_pipeline The system is waiting for tasks: {<Task pending name='Task-1539' coro=<MiniServer.start_loxone() running at /Users/juerg.luthiger/projects-dev/home-assistant/core/config/custom_components/loxone/miniserver.py:167> wait_for=<Future pending cb=[Task.task_wakeup()] created at /Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/asyncio/base_events.py:449> cb=[set.remove()] created at /Users/juerg.luthiger/projects-dev/home-assistant/core/homeassistant/util/async_.py:40>}

I made a fix to prevent this blocking call. Please check carefully, if no side-effect will be introduced. I cannot estimate all the consequences.

JoDehli commented 1 week ago

@jluthiger I included your request. But I never got this blocking messages. So please check the lastest master branch before I make another version.

I changed the CustomSensor implementation. We should use the _attributes and not override the functions. I wrote all this long time ago before homeassistant had this very useful attributes. This can be updated in all places but as I already mentioned I work on a complete different branch at the moment and all renaming and cleanups must be transferred to the other branch (not public) so at the moment it is better only concentrate on the real issues.

Thanks for your help.

jluthiger commented 1 week ago

Great. Just checked the master branch. Works perfectly! Thanks a lot.