Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

SmartDeviceException: Communication error on system:set_relay_state #309

Copy link
Copy link
@IllyShaieb

Description

@IllyShaieb
Issue body actions

I have a smart plug, KP105(UK), but when I try to interact with my device within my python program I now get the following errors:

╭─────────────────────────────── Traceback (most recent call last) ────────────────────────────────╮
│                                                                                                  │
│ C:\Code\ENVIRONMENTS\ace-env\lib\site-packages\kasa\smartdevice.py:237 in _query_helper          │
│                                                                                                  │
│   234 │   │   request = self._create_request(target, cmd, arg, child_ids)                        │
│   235 │   │                                                                                      │
│   236 │   │   try:                                                                               │
│ ❱ 237 │   │   │   response = await self.protocol.query(request=request)                          │
│   238 │   │   except Exception as ex:                                                            │
│   239 │   │   │   raise SmartDeviceException(f"Communication error on {target}:{cmd}") from ex   │
│   240                                                                                            │
│ C:\Code\ENVIRONMENTS\ace-env\lib\site-packages\kasa\protocol.py:71 in query                      │
│                                                                                                  │
│    68 │   │   timeout = TPLinkSmartHomeProtocol.DEFAULT_TIMEOUT                                  │
│    69 │   │                                                                                      │
│    70 │   │   async with self.query_lock:                                                        │
│ ❱  71 │   │   │   return await self._query(request, retry_count, timeout)                        │
│    72 │                                                                                          │
│    73 │   async def _connect(self, timeout: int) -> bool:                                        │
│    74 │   │   """Try to connect or reconnect to the device."""                                   │
│                                                                                                  │
│ C:\Code\ENVIRONMENTS\ace-env\lib\site-packages\kasa\protocol.py:130 in _query                    │
│                                                                                                  │
│   127 │   │   │   │   await self.close()                                                         │
│   128 │   │   │   │   if retry >= retry_count:                                                   │
│   129 │   │   │   │   │   _LOGGER.debug("Giving up on %s after %s retries", self.host, retry)    │
│ ❱ 130 │   │   │   │   │   raise SmartDeviceException(                                            │
│   131 │   │   │   │   │   │   f"Unable to connect to the device: {self.host}"                    │
│   132 │   │   │   │   │   )                                                                      │
│   133 │   │   │   │   continue                                                                   │
╰──────────────────────────────────────────────────────────────────────────────────────────────────╯
SmartDeviceException: Unable to connect to the device:  x.x.x.x

The above exception was the direct cause of the following exception:

╭─────────────────────────────── Traceback (most recent call last) ────────────────────────────────╮
│                                                                                                  │
│ C:\Code\ENVIRONMENTS\ace-env\ACE\ace.py:66 in <module>                                           │
│                                                                                                  │
│   63 │   │   intent, text = response.split(",") if "," in response else (response,               │
│   64 │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   None)                   │
│   65 │   │   try:                                                                                │
│ ❱ 66 │   │   │   response, continue_ = manager.execute(intent, text)                             │
│   67 │   │   │   console.print("Response: ", response, "\n")                                     │
│   68 │   │   │                                                                                   │
│   69 │   │   │   if not continue_:                                                               │
│ C:\Code\ENVIRONMENTS\ace-env\ACE\components\utils.py:41 in execute                               │
│                                                                                                  │
│   38 │   │   │   and a flag."""
│   39 │   │   intent_obj = self._get_intent_obj(intent)                                           │
│   40 │   │   if intent_obj.requires_text():                                                      │
│ ❱ 41 │   │   │   return intent_obj.execute(text)                                                 │
│   42 │   │   return intent_obj.execute()                                                         │
│   43 │                                                                                           │
│   44 │   def _create_intents(self) -> dict:                                                      │
│                                                                                                  │
│ C:\Code\ENVIRONMENTS\ace-env\ACE\components\intents\devices.py:101 in execute                    │
│                                                                                                  │
│    98 │   │   │   ]                                                                              │
│    99 │   │   │   device_name = sub_replace(matches[-1], stop_words)                             │
│   100 │   │   │   if "on" in text:                                                               │
│ ❱ 101 │   │   │   │   if self.device_manager.on(device_name):                                    │
│   102 │   │   │   │   │   return (f"Turning on '{device_name}'...", True)                        │
│   103 │   │   │   │   return (f"I'm sorry, I can't find '{device_name}'.", True)                 │
│   104 │   │   │   if "off" in text:                                                              │
│                                                                                                  │
│ C:\Code\ENVIRONMENTS\ace-env\ACE\components\intents\devices.py:66 in on                          │
│                                                                                                  │
│    63 │                                                                                          │
│    64 │   def on(self, device_name: str) -> bool:                                                │
│    65 │   │   try:                                                                               │
│ ❱  66 │   │   │   return self.device_config[device_name].on()                                    │
│    67 │   │   except KeyError:                                                                   │
│    68 │   │   │   return False                                                                   │
│    69                                                                                            │
│                                                                                                  │
│ C:\Code\ENVIRONMENTS\ace-env\ACE\components\intents\devices.py:36 in on                          │
│                                                                                                  │
│    33 class Plug(Device):                                                                        │
│    34 │   def on(self) -> bool:                                                                  │
│    35 │   │   if self.model.lower() == "kasa":                                                   │
│ ❱  36 │   │   │   asyncio.run(SmartPlug(self.ip).turn_on())                                      │
│    37 │   │   │   return True                                                                    │
│    38 │                                                                                          │
│    39 │   def off(self) -> bool:                                                                 │
│                                                                                                  │
│ c:\users\illys\appdata\local\programs\python\python39\lib\asyncio\runners.py:44 in run           │
│                                                                                                  │
│   41 │   │   events.set_event_loop(loop)                                                         │
│   42 │   │   if debug is not None:                                                               │
│   43 │   │   │   loop.set_debug(debug)                                                           │
│ ❱ 44 │   │   return loop.run_until_complete(main)                                                │
│   45 │   finally:                                                                                │
│   46 │   │   try:                                                                                │
│   47 │   │   │   _cancel_all_tasks(loop)                                                         │
│                                                                                                  │
│ c:\users\illys\appdata\local\programs\python\python39\lib\asyncio\base_events.py:642 in          │
│ run_until_complete                                                                               │
│                                                                                                  │
│    639 │   │   if not future.done():                                                             │
│    640 │   │   │   raise RuntimeError('Event loop stopped before Future completed.')             │
│    641 │   │                                                                                     │
│ ❱  642 │   │   return future.result()                                                            │
│    643 │                                                                                         │
│    644 │   def stop(self):                                                                       │
│    645 │   │   """Stop running the event loop.                                                   │
│                                                                                                  │
│ C:\Code\ENVIRONMENTS\ace-env\lib\site-packages\kasa\smartplug.py:53 in turn_on                   │
│                                                                                                  │
│   50 │                                                                                           │
│   51 │   async def turn_on(self, **kwargs):                                                      │
│   52 │   │   """Turn the switch on."""                                                           │
│ ❱ 53 │   │   return await self._query_helper("system", "set_relay_state", {"state": 1})          │
│   54 │                                                                                           │
│   55 │   async def turn_off(self, **kwargs):                                                     │
│   56 │   │   """Turn the switch off."""                                                          │
│                                                                                                  │
│ C:\Code\ENVIRONMENTS\ace-env\lib\site-packages\kasa\smartdevice.py:239 in _query_helper          │
│                                                                                                  │
│   236 │   │   try:                                                                               │
│   237 │   │   │   response = await self.protocol.query(request=request)                          │
│   238 │   │   except Exception as ex:                                                            │
│ ❱ 239 │   │   │   raise SmartDeviceException(f"Communication error on {target}:{cmd}") from ex   │
│   240 │   │                                                                                      │
│   241 │   │   if target not in response:                                                         │
│   242 │   │   │   raise SmartDeviceException(f"No required {target} in response: {response}")    │
╰──────────────────────────────────────────────────────────────────────────────────────────────────╯
SmartDeviceException: Communication error on system:set_relay_state

I have tried upgrading python-kasa from v0.4.0 => v0.4.1 but still get the same errors.

If I use the interactive python shell, I can run the commands successfully to turn on and off the device.

Please could someone advise on how to fix this issue?

Reactions are currently unavailable

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.