kubawolanin / ha-openhab

WORK IN PROGRESS 🏠 openHAB custom integration for Home Assistant
MIT License
15 stars 5 forks source link

HA Integration did not refresh state of binär contact from OH #22

Open Here4uW opened 1 year ago

Here4uW commented 1 year ago

Version OH 3.3.0 Release Build openHAB

Version HA Home Assistant 2022.10.5 Supervisor 2022.10.0 Operating System 9.3 Frontend 20221010.0 - latest

The Log file give a warning out everytime i refresh the integration. (When i go to the three points of the integration and choose the first option reload)

Logger: homeassistant.helpers.frame Source: helpers/frame.py:74 First occurred: 1. November 2022, 21:14:35 (116 occurrences) Last logged: 10:06:37

Detected code that uses str for device registry entry_type. This is deprecated and will stop working in Home Assistant 2022.3, it should be updated to use DeviceEntryType instead. Please report this issue

The Log in the integration did not show changes of the OH - only if i refresh manuall.

When i open the attribut of one of the enität i see following information

Attribute Category window Group names Hostname xx.xx.xx.xx ID openhab_CP400Meldepunkte_BuroFenster Integration openhab Is group false Label Büro Fenster Api link http://xx.xx.xx.xx:8080/rest/items/CP400Meldepunkte_BuroFenster Main ui link http://xx.xx.xx.xx:8080/settings/items/CP400Meldepunkte_BuroFenster Name CP400Meldepunkte_BuroFenster Tags Office Type Contact Raw state OPEN Unit of measure

When i open the Api Link listed in the Atribut of the enität i see the closed information from OH

{"link":"http://xx.xx.xx.xx:8080/rest/items/CP400Meldepunkte_BuroFenster","state":"CLOSED","stateDescription":{"pattern":"%s","readOnly":true,"options":[]},"editable":true,"type":"Contact","name":"CP400Meldepunkte_BuroFenster","label":"Büro Fenster ","category":"window","tags":["Office"],"groupNames":[]}

After Manuall refreshing of the integration it will be shown correctly in HA.

Regarding the warning "uses str for device registry entry_type" i find this in the home-assistand.log

2022-11-01 21:14:35.351 WARNING (MainThread) [homeassistant.helpers.frame] Detected code that uses str for device registry entry_type. This is deprecated and will stop working in Home Assistant 2022.3, it should be updated to use DeviceEntryType instead. Please report this issue. Stack (most recent call last): File "/usr/local/lib/python3.10/runpy.py", line 196, in _run_module_as_main return _run_code(code, main_globals, None, File "/usr/local/lib/python3.10/runpy.py", line 86, in _run_code exec(code, run_globals) File "/usr/src/homeassistant/homeassistant/main.py", line 203, in sys.exit(main()) File "/usr/src/homeassistant/homeassistant/main.py", line 191, in main exit_code = runner.run(runtime_conf) File "/usr/src/homeassistant/homeassistant/runner.py", line 119, in run return loop.run_until_complete(setup_and_run_hass(runtime_config)) File "/usr/local/lib/python3.10/asyncio/base_events.py", line 633, in run_until_complete self.run_forever() File "/usr/local/lib/python3.10/asyncio/base_events.py", line 600, in run_forever self._run_once() File "/usr/local/lib/python3.10/asyncio/base_events.py", line 1896, in _run_once handle._run() File "/usr/local/lib/python3.10/asyncio/events.py", line 80, in _run self._context.run(self._callback, *self._args) File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 573, in _async_add_entity device = device_registry.async_get_or_create(**processed_dev_info) # type: ignore[arg-type] File "/usr/src/homeassistant/homeassistant/helpers/device_registry.py", line 349, in async_get_or_create report( # type: ignore[unreachable] File "/usr/src/homeassistant/homeassistant/helpers/frame.py", line 74, in report _LOGGER.warning(msg, stack_info=True)

Crumpy1978 commented 1 year ago

Hello,

I notice excactly the same behavior on HA 2022.11.1 The only way to refresh switches etc is to manually refresh the ha-openhab integration manually.

Is there anyone who understands this kind of code to guide on what should be fixed ?

Best regards

kovacsla commented 1 year ago

I have same problem, but I made a workaround. I restart the integration every 5 minute. :) It is working.

automations.yaml

  trigger:
    - platform: time_pattern
        # You can also match on interval. This will match every 5 minutes
      minutes: "/5"
  action: 
    - service: homeassistant.reload_config_entry
      data:
        device_id: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
McPierre93 commented 1 year ago

I have same problem, but I made a workaround. I restart the integration every 5 minute. :) It is working.

automations.yaml

  trigger:
    - platform: time_pattern
        # You can also match on interval. This will match every 5 minutes
      minutes: "/5"
  action: 
    - service: homeassistant.reload_config_entry
      data:
        device_id: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

Same problem, but the automation works greats. Good Idea :)

helljol commented 1 year ago

Hi @kubawolanin ,

Would you please fix the refresh state not working ? this is probably due to the 2022-3 breaking change. I just discover your integration and i would love to use it to sync some OH items in HA.

This integration was a great idea.

Namek commented 1 year ago

I must inform you all that Kuba has passed away a few months ago. Please consider making a fork and link back in a new issue if you're interested.

hauserbauten commented 1 year ago

very sorry to hear this @Namek 😢 Kuba in the prime of his life. shocked and saddened that such a talent is no longer with us. We shall endeavour to carry his torch forward

bob-tm commented 7 months ago

entity.py line 145

fixed version

async def async_added_to_hass(self) -> None:
        """Connect to dispatcher listening for entity data notifications."""
        self.async_on_remove(
            self.coordinator.async_add_listener(self._handle_coordinator_update)
        )
kovacsla commented 7 months ago

Hi @bob-tm I tried your modification and it seems to work. Thanks a lot!

bob-tm commented 6 months ago

Updated version https://github.com/bob-tm/ha-openhab/ It's more about adding devireg thermostat support, but some bugs were also fixed.

Smarthome-Creator commented 3 months ago

@bob-tm, thank you for keeping this great project alive.

Smarthome-Creator commented 3 months ago

Updated version https://github.com/bob-tm/ha-openhab/ It's more about adding devireg thermostat support, but some bugs were also fixed.

I have a question or perhaps a mistake in my thinking. A very simple example. I have switched on a switch in OH, but it is not set to ON in HA. Why is that? Do I have to define this manually somewhere? Or does reading out the status only work from HA to OH?

I had thought I could also use it to transfer the status of the switch from OH to HA. I need this because I use it to switch a few things for which there are no integrations in HA. For example, ssh commands that take longer than 60 seconds for a response.

kovacsla commented 1 week ago

Hi @bob-tm, I would like to ask you, do you fix bugs in openHAB HA integration? If yes, how can I report the bugs to you? I couldn't find a way on "https://github.com/bob-tm/ha-openhab". Thanks in advance for your reply.

bob-tm commented 1 week ago

Hi @bob-tm, I would like to ask you, do you fix bugs in openHAB HA integration? If yes, how can I report the bugs to you? I couldn't find a way on "https://github.com/bob-tm/ha-openhab". Thanks in advance for your reply.

Hi, I opened issues on my repository. But I only focused on devi integrations and my devices work well :)