ZacheryThomas / homeassistant-smartrent

Home Assistant Custom Component for SmartRent Locks 🔐, Thermostats 🌡, Sensors 💧 and Switches💡
MIT License
84 stars 3 forks source link

Issue Unlocking/Locking After Newest HA Update #14

Closed Palmer-Pesta closed 1 year ago

Palmer-Pesta commented 1 year ago

First, I want to say great job on this integration; I use it a lot.

Recently I've hit this stack trace when trying to lock/unlock. Everything else works, and I've tried to uninstall, wipe pvcs, etc.

Logger: homeassistant.components.websocket_api.http.connection
Source: components/lock/__init__.py:95
Integration: Home Assistant WebSocket API (documentation, issues)
First occurred: 6:43:27 PM (1 occurrences)
Last logged: 6:43:27 PM

SmartrentLock.async_lock() got an unexpected keyword argument 'entity_id'
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/websocket_api/commands.py", line 200, in handle_call_service
    await hass.services.async_call(
  File "/usr/src/homeassistant/homeassistant/core.py", line 1787, in async_call
    task.result()
  File "/usr/src/homeassistant/homeassistant/core.py", line 1824, in _execute_service
    await cast(Callable[[ServiceCall], Awaitable[None]], handler.job.target)(
  File "/usr/src/homeassistant/homeassistant/helpers/entity_component.py", line 213, in handle_service
    await service.entity_service_call(
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 681, in entity_service_call
    future.result()  # pop exception if have
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 968, in async_request_call
    await coro
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 721, in _handle_entity_call
    await result
  File "/usr/src/homeassistant/homeassistant/components/lock/__init__.py", line 95, in _async_lock
    await entity.async_lock(**service_call.data)
TypeError: SmartrentLock.async_lock() got an unexpected keyword argument 'entity_id'
Palmer-Pesta commented 1 year ago

Note: After looking at breaking changes, it might be the upgrade to python 3.9 -> 3.10.

tjleach98 commented 1 year ago

I also had this problem and it seems to be async_lock and async_unlock should be accepting arguments but currently are not. I made a small change and now the locks are working. I don't know a lot about this system, but I am basing it off this change I saw in the Home Assistant Core repo.

---     async def async_lock(self):
+++     async def async_lock(self, **kwargs):

---     async def async_unlock(self):
+++     async def async_unlock(self, **kwargs):
ZacheryThomas commented 1 year ago

Hi @Palmer-Pesta! Glad to hear this integration is working out for you!

Guess you saw my latest release. Low key I haven't updated my HA instance yet & make sure everything works out there but i'm guessing its all good since the issue is closed! Let me know if theres any other issues in general though

Also thanks for the help @tjleach98!

Palmer-Pesta commented 1 year ago
This error originated from a custom integration.

Logger: homeassistant.loader
Source: custom_components/smartrent/lock.py:63
Integration: SmartRent (documentation, issues)
First occurred: 3:01:20 PM (2 occurrences)
Last logged: 3:04:30 PM

Unexpected exception importing platform custom_components.smartrent.lock
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/loader.py", line 749, in get_platform
    cache[full_name] = self._import_platform(platform_name)
  File "/usr/src/homeassistant/homeassistant/loader.py", line 766, in _import_platform
    return importlib.import_module(f"{self.pkg_path}.{platform_name}")
  File "/usr/local/lib/python3.10/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 883, in exec_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "/config/custom_components/smartrent/lock.py", line 22, in <module>
    class SmartrentLock(LockEntity):
  File "/config/custom_components/smartrent/lock.py", line 63, in SmartrentLock
    async def async_lock(self, **kwargs: Any):
NameError: name 'Any' is not defined
Palmer-Pesta commented 1 year ago

Apologies, I might have too hastefully resolved this issue. It looks like it is now rejecting the Any keyword.

Palmer-Pesta commented 1 year ago
---     async def async_lock(self, **kwargs: Any):
+++  async def async_lock(self, **kwargs):

---    async def async_unlock(self, **kwargs: Any):
+++ async def async_unlock(self, **kwargs):

Please note I made the following changes and the integration works again.

anthonymkz commented 1 year ago

Since upgrading not only does my lock not work, but it can't even be set up. Please help!

Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/loader.py", line 749, in get_platform cache[full_name] = self._import_platform(platform_name) File "/usr/src/homeassistant/homeassistant/loader.py", line 766, in _import_platform return importlib.import_module(f"{self.pkg_path}.{platform_name}") File "/usr/local/lib/python3.10/importlib/init.py", line 126, in import_module return _bootstrap._gcd_import(name[level:], package, level) File "", line 1050, in _gcd_import File "", line 1027, in _find_and_load File "", line 1006, in _find_and_load_unlocked File "", line 688, in _load_unlocked File "", line 883, in exec_module File "", line 241, in _call_with_frames_removed File "/config/custom_components/smartrent/lock.py", line 22, in class SmartrentLock(LockEntity): File "/config/custom_components/smartrent/lock.py", line 63, in SmartrentLock async def async_lock(self, **kwargs: Any): NameError: name 'Any' is not defined 2023-02-04 11:02:50.097 ERROR (MainThread) [homeassistant.setup] Unable to prepare setup for platform smartrent.lock: Platform not found (Exception importing custom_components.smartrent.lock). 2023-02-04 11:02:56.630 WARNING (MainThread) [homeassistant.components.media_player] Setup of media_player platform dlna_dmr is taking over 10 seconds. 2023-02-04 11:02:56.631 WARNING (MainThread) [homeassistant.components.media_player] Setup of media_player platform dlna_dmr is taking over 10 seconds. 2023-02-04 11:06:43.274 WARNING (MainThread) [homeassistant.helpers.service] Unable to find referenced entities lock.front_door_lock or it is/they are currently not available 2023-02-04 11:06:44.290 WARNING (MainThread) [homeassistant.helpers.service] Unable to find referenced entities lock.front_door_lock or it is/they are currently not available 2023-02-04 11:06:44.455 WARNING (MainThread) [homeassistant.helpers.service] Unable to find referenced entities lock.front_door_lock or it is/they are currently not available 2023-02-04 11:06:44.598 WARNING (MainThread) [homeassistant.helpers.service] Unable to find referenced entities lock.front_door_lock or it is/they are currently not available

Palmer-Pesta commented 1 year ago

Same issue as above. You can edit the code by control + f to find it in vscode (under custom_components) and remove the : Any. Note: you will then need to remove the device integration and readd it. Don't redownload or uninstall in hacs only the HA devices page. Or just wait until a new release of this library is published.

ZacheryThomas commented 1 year ago

Sorry ya'll! I just pushed out a new release. Should restore the functionality of the locks.

I was able to update my HA instance to latest and test it there too. So the original issue should be fixed as well.

Let me know if anything else is goin wrong and I can take a look at things

Palmer-Pesta commented 1 year ago

Confirmed that these changes worked. Closing the issue now. Thanks for your help, Zach!

ZacheryThomas commented 1 year ago

It's no problem! Thanks for the great feedback & helping me test out stuff!

yousefmansy1 commented 1 year ago

Sorry for noob question, but I am also having this same issue. I've deleted and reinstalled the integration, and my Home assistant is up to date (2023.2.3)

Yet I get the following error when triggering lock/unlock from the frontend:

Failed to call service lock/lock. SmartrentLock.async_lock() got an unexpected keyword argument 'entity_id'
ZacheryThomas commented 1 year ago

@yousefmansy1 after you reinstalled the SmartRent integration have you restarted your Homeassistant instance?

yousefmansy1 commented 1 year ago

Yes I have restarted my HA instance.

Is there a way to validate the version of the plug in I'm using?

ZacheryThomas commented 1 year ago

Im actually not sure if theres a way to view the info reliably with the UI 🤔

But if you have command line access you can output some information that contains the version number for the integration. You should be able to navigate to wherever homeassistant stores config and then view the file in custom_components/smartrent/manifest.json

$ cat config/custom_components/smartrent/manifest.json
{
  "domain": "smartrent",
  "name": "SmartRent",
  "documentation": "https://github.com/ZacheryThomas/homeassistant-smartrent",
  "issue_tracker": "https://github.com/ZacheryThomas/homeassistant-smartrent/issues",
  "dependencies": [],
  "codeowners": ["@zacherythomas"],
  "config_flow": true,
  "requirements": ["smartrent.py==0.3.1"],
  "iot_class": "cloud_push",
  "version": "0.3.5"
}
yousefmansy1 commented 1 year ago

Yep that looks to be the issue. Despite reinstalling, I'm somehow on 0.3.2

{
  "domain": "smartrent",
  "name": "SmartRent",
  "documentation": "https://github.com/ZacheryThomas/homeassistant-smartrent",
  "issue_tracker": "https://github.com/ZacheryThomas/homeassistant-smartrent/issues",
  "dependencies": [],
  "codeowners": ["@zacherythomas"],
  "config_flow": true,
  "requirements": ["smartrent.py==0.3.0"],
  "iot_class": "cloud_push",
  "version": "0.3.2"
}

So pt2 of noob question, how can I ensure I'm installing the latest version of an integration? I'm using the web interface but perhaps there's a better way?

ZacheryThomas commented 1 year ago

@yousefmansy1 what normally works for me is when you are on the HACS page for Smartrent is clicking:

image

If thats not working at all you can delete your custom-component/smartrent directory and then install things manually. You can download the code as a zip file, unzip it then move the content from my repos homeassistant-smartrent/custom-component/smartrent into the right location in your HA instance

Here is some more info about that method: https://github.com/ZacheryThomas/homeassistant-smartrent#installing-manually

yousefmansy1 commented 1 year ago

I had a major brain fart, I forgot about the HACS store showing its own updates. It updated perfectly through there and my lock integration works perfectly fine now.

Thanks!

ZacheryThomas commented 1 year ago

haha no problem!! Glad you got everything working out!