Skip to content

Conversation

@cebtenzzre
Copy link
Contributor

The bug reported is that HASS set_plugin_state can return an error which wasn't handled before, resulting in a TypeError, as reported by both TimW and xtalker (Bob) on Discord:

File "/conf/apps/solar/power_generation_analysis_v3.py", line 466, in update_analysis_sensors
  self.set_state(sensor_name, state=seconds, attributes=attributes, namespace="default")
File "/usr/local/lib/python3.12/site-packages/appdaemon/utils.py", line 289, in wrapper
  return run_coroutine_threadsafe(self, coro, timeout=timeout)
File "/usr/local/lib/python3.12/site-packages/appdaemon/utils.py", line 615, in run_coroutine_threadsafe
  return future.result(timeout.total_seconds())
File "/usr/local/lib/python3.12/concurrent/futures/_base.py", line 456, in result
  return self.__get_result()
File "/usr/local/lib/python3.12/concurrent/futures/_base.py", line 401, in __get_result
  raise self._exception
File "/usr/local/lib/python3.12/site-packages/appdaemon/adapi.py", line 1789, in set_state
  return await self.AD.state.set_state(
File "/usr/local/lib/python3.12/site-packages/appdaemon/state.py", line 793, in set_state
  if "entity_id" in result:
     ^^^^^^^^^^^^^^^^^^^^^
TypeError: argument of type 'ClientResponseError' is not iterable

This PR adds error handling in set_plugin_state consistent with get_plugin_state to fix that error. It also adds fallback to local handling on error, instead of doing nothing. (Let me know if you think that makes sense.)

from enum import Enum
from logging import Logger
from pathlib import Path
from typing import TYPE_CHECKING, Any, Awaitable, List, Literal, Optional, Protocol, Set, overload
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oops, forgot you could import this from typing too :)

@acockburn acockburn merged commit 27d7ac4 into AppDaemon:dev Nov 30, 2025
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants