yangqian / hass-cozylife

third party cozylife integration
MIT License
66 stars 14 forks source link

Sync Availability #9

Closed kozfelipe closed 1 year ago

kozfelipe commented 1 year ago

Everytime someone uses the actual physical switch it get lost in synchronization

Traceback (most recent call last):
  File "/config/custom_components/cozylife/tcp_client.py", line 252, in _only_send
    self._connect.send(self._get_package(cmd, payload))
BrokenPipeError: [Errno 32] Broken pipe

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/websocket_api/commands.py", line 230, in handle_call_service
    await hass.services.async_call(
  File "/usr/src/homeassistant/homeassistant/core.py", line 2035, in async_call
    response_data = await coro
                    ^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/core.py", line 2072, in _execute_service
    return await target(service_call)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/entity_component.py", line 235, in handle_service
    return await service.entity_service_call(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 876, in entity_service_call
    response_data = await _handle_entity_call(
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 948, in _handle_entity_call
    result = await task
             ^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/light/__init__.py", line 591, in async_handle_light_off_service
    await light.async_turn_off(**filter_turn_off_params(light, params))
  File "/config/custom_components/cozylife/light.py", line 554, in async_turn_off
    await super().async_turn_off(*kwargs)
  File "/config/custom_components/cozylife/light.py", line 234, in async_turn_off
    await self.hass.async_add_executor_job(self._tcp_client.control, {
  File "/usr/local/lib/python3.11/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/cozylife/tcp_client.py", line 268, in control
    self._only_send(CMD_SET, payload)
  File "/config/custom_components/cozylife/tcp_client.py", line 254, in _only_send
    self._connect.send(self._get_package(cmd, payload))
BrokenPipeError: [Errno 32] Broken pipe
yangqian commented 1 year ago

The error suggests that the switch rebooted. Are you connecting the switch to a fan (inductive load) instead of light bulb (resistive load)?

yangqian commented 1 year ago

It will resync after about 5 minutes?

kozfelipe commented 1 year ago

It is a light bulb load. Isn't 5 min too long?

yangqian commented 1 year ago

It is controled by the parameter SCAN_INTERVAL = timedelta(seconds=240) You could adjust this parameters. I'm not using the physical and hass at the same time that often so it does not bother me.

But your problem may come from a loose connection between cables since switching should not disconnect the device.

kozfelipe commented 1 year ago

SCAN_INTERVAL from custom_components/cozylife/light.py right? I will tweak it later, thanks

yangqian commented 1 year ago

SCAN_INTERVAL from custom_components/cozylife/light.py right? I will tweak it later, thanks

Sorry, I made a mistake. It depends. If you treat the "physical switch" as a hass light in the yaml config file, then, we need to look at the SWITCH_SCAN_INTERVAL in light.py which is 20 seconds now. If we treat the "physical switch" as a hass switch, we need to look at the SCAN_INTERVAL in switch.py.

kozfelipe commented 1 year ago

yes it is configured as light

light:
  - platform: cozylife
    lights:
      - ip: 192.168.0.16
        did: 69965988249494ab272d
        pid: p93sfg
        dmn: Smart Bulb Light
        dpid: [1, 2, 3, 4, 5, 7, 8, 9, 13, 14]
yangqian commented 1 year ago

yes it is configured as light

light:
  - platform: cozylife
    lights:
      - ip: 192.168.0.16
        did: 69965988249494ab272d
        pid: p93sfg
        dmn: Smart Bulb Light
        dpid: [1, 2, 3, 4, 5, 7, 8, 9, 13, 14]

You probably do not need to do anything then. Do you get response in about 20 seconds?

kozfelipe commented 1 year ago

I will use this light in a room that does not need a switch as you described, thanks