Closed smithbill17 closed 2 years ago
Hi @smithbill17 thanks for reporting this. I don't have the time right now, but I will be happy to merge a PR if you can do it
Sorry, I don't know how to develop Python stuff - I'm an end-user, so wouldn't know where to begin.
Also, the failed integration prevents Home Assistant from being restarted as it generates the below error everytime you try to restart Home Assistant:
Failed to restart Home AssistantCore
The system cannot restart because the configuration is not valid: Platform error switch.switchbot_press - cannot import name 'SwitchDevice' from 'homeassistant.components.switch' (/usr/src/homeassistant/homeassistant/components/switch/__init__.py)
i didn't try but pull this commit https://github.com/cagnulein/switchbot_press/commit/b936c9fc982ac011b38b35493b50d14b917fb1c5 and let me know if it's better or not. Thanks
Sorry - I don't really know how you "pull a commit" but looking at the change made to the manifest.json file, the only change is to bump the version number to 0.8.1, so I went to my existing manifest.json file in the switchbot_press custom component & edited the version number & saved it. But it's made no difference, I still get the below error when trying to restart Home Assistant:
Platform error switch.switchbot_press - cannot import name 'SwitchDevice' from 'homeassistant.components.switch' (/usr/src/homeassistant/homeassistant/components/switch/__init__.py)
@smithbill17 no i did another change before that. please download the new zip file https://github.com/cagnulein/switchbot_press/archive/refs/heads/master.zip
Okay, downloaded the zip, extracted the 3 files and copied them up to switchbot_press in my custom components, restarted Home Assistant and it seems to be working again - brilliant! Thanks for the quick fix! What exactly was the issue with the new HA v2022.2.0 ?
@smithbill17 great! they changed the way how call a switch device.
I may have spoken too soon. I tried controlling my SwitchBot a 2nd time from within HomeAssistant (as normal) and it generated this error:
[2897047336] [Errno 32] Broken pipe
Traceback (most recent call last):
File "/usr/local/lib/python3.9/site-packages/switchbot/__init__.py", line 93, in _sendcommand
send_success = self._writekey(command)
File "/usr/local/lib/python3.9/site-packages/switchbot/__init__.py", line 77, in _writekey
hand = hand_service.getCharacteristics(HANDLE)[0]
File "/usr/local/lib/python3.9/site-packages/bluepy/btle.py", line 144, in getCharacteristics
self.chars = [] if self.hndEnd <= self.hndStart else self.peripheral.getCharacteristics(self.hndStart, self.hndEnd)
File "/usr/local/lib/python3.9/site-packages/bluepy/btle.py", line 508, in getCharacteristics
rsp = self._getResp('find')
File "/usr/local/lib/python3.9/site-packages/bluepy/btle.py", line 407, in _getResp
resp = self._waitResp(wantType + ['ntfy', 'ind'], timeout)
File "/usr/local/lib/python3.9/site-packages/bluepy/btle.py", line 361, in _waitResp
self._stopHelper()
File "/usr/local/lib/python3.9/site-packages/bluepy/btle.py", line 293, in _stopHelper
self._helper.stdin.flush()
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 190, in handle_call_service
await hass.services.async_call(
File "/usr/src/homeassistant/homeassistant/core.py", line 1630, in async_call
task.result()
File "/usr/src/homeassistant/homeassistant/core.py", line 1667, in _execute_service
await cast(Callable[[ServiceCall], Awaitable[None]], handler.job.target)(
File "/usr/src/homeassistant/homeassistant/helpers/entity_component.py", line 204, in handle_service
await self.hass.helpers.service.entity_service_call(
File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 668, in entity_service_call
future.result() # pop exception if have
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 921, in async_request_call
await coro
File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 705, in _handle_entity_call
await result
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 975, in async_turn_on
await self.hass.async_add_executor_job(ft.partial(self.turn_on, **kwargs))
File "/usr/local/lib/python3.9/concurrent/futures/thread.py", line 52, in run
result = self.fn(*self.args, **self.kwargs)
File "/config/custom_components/switchbot_press/switch.py", line 61, in turn_on
if self._device.press():
File "/usr/local/lib/python3.9/site-packages/switchbot/__init__.py", line 117, in press
return self._sendcommand(PRESS_KEY, self._retry_count)
File "/usr/local/lib/python3.9/site-packages/switchbot/__init__.py", line 97, in _sendcommand
self._disconnect()
File "/usr/local/lib/python3.9/site-packages/switchbot/__init__.py", line 58, in _disconnect
self._device.disconnect()
File "/usr/local/lib/python3.9/site-packages/bluepy/btle.py", line 453, in disconnect
self._writeCmd("disc\n")
File "/usr/local/lib/python3.9/site-packages/bluepy/btle.py", line 305, in _writeCmd
self._helper.stdin.flush()
BrokenPipeError: [Errno 32] Broken pipe
@smithbill17 this seems an error with your bluetooth dongle, restart it and retry.
I'm just using the inbuilt Bluetooth on RPi4b, so I just restarted the host & tried again & this time didn't get the error.
Only issue appearing in the log is the below warning. Thanks for your quick work!
Logger: homeassistant.helpers.entity Source: helpers/entity.py:574 First occurred: 13:37:01 (1 occurrences) Last logged: 13:37:01
Entity switch.switchbot_press (<class 'custom_components.switchbot_press.switch.SwitchBot_press'>) implements device_state_attributes. Please report it to the custom component author.
After upgrading Home Assistant to v2022.2.0, this integration is failing to load. Can you please fix this issue as soon as you can?