Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: Entity.set_state() takes 1 positional argument but 2 were given #2191

Open
Mike-Allen opened this issue Jan 21, 2025 · 1 comment
Labels
bug Something isn't working work_in_progress Isse or PR that is evolving and shouldn't;t be aged out

Comments

@Mike-Allen
Copy link

What happened?

This is interesting.

The code is scheduled to run every 15 minutes. The night before last the app was started about 7:40 PM and ran fine until midnight. Then it started throwing the errors. Each 15 minutes it would attempt to run again but fail. (Failing at midnight is a coincidence and isn't part of the problem. The problem has occurred at other times.)

Sometimes the error occurs sooner after the app is started, maybe after a half-hour or so.

The problem code is: (There's some more context below in the code section)
self.high_temp_ent.set_state(fTemperature)

Changing the code to the following seems to fix the problem:
self.high_temp_ent.set_state(state = fTemperature)

As can be seen self.high_temp_ent.set_state is an AppDaemon entity.

It's odd that it works for a while. Although the log entry says that the app and thread are pinned I did not explicitly pin either of them. (It's probably the default behavior but I thought I'd mention it.)

It's not a problem for me. The fix works. The app has now been running for over 24 hours and hasn't had any problems.

I would add that I saw the deprecation notice by Frenck and I understand and support AppDaemon's position. Home Assistant wouldn't have the same value without AppDaemon. Home Assistant provides the building blocks. AppDaemon allows me to create... magic.

I have two Home Assistant instances. One is "old" running Home Assistant and AppDaemon in Python virtual environments. (I need to upgrade but dread the z-wave upgrade.) The other instance is new and uses Frenck's add-on. I can use AppDaemon in a virtual environment or I can add AppDaemon through Docker if I need to. There's no way that I'm running Home Assistant without AppDaemon.

Version

4.4.2

Installation type

Home Assistant add-on

Relevant log output

2025-01-20 08:15:00.007032 WARNING GetWeather: ------------------------------------------------------------
2025-01-20 08:15:00.007286 WARNING GetWeather: Unexpected error in worker for App GetWeather:
2025-01-20 08:15:00.007399 WARNING GetWeather: Worker Ags: {'id': '5f43680bacec4282b24d83f56c8ffb39', 'name': 'GetWeather', 'objectid': 'f8d6794d75da4007a3c321a3e2b3d137', 'type': 'scheduler', 'function': <bound method CabinWeather.getWeather_CB of <getWeather.CabinWeather object at 0x7faecbe56190>>, 'pin_app': True, 'pin_thread': 1, 'kwargs': {'interval': 900, '__thread_id': 'thread-1'}}
2025-01-20 08:15:00.008364 WARNING GetWeather: ------------------------------------------------------------
2025-01-20 08:15:00.008888 WARNING GetWeather: Traceback (most recent call last):
  File "/usr/lib/python3.11/site-packages/appdaemon/threading.py", line 1022, in worker
    funcref(self.AD.sched.sanitize_timer_kwargs(app, args["kwargs"]))
  File "/config/apps/getWeather.py", line 230, in getWeather_CB
    self.processWeather()
  File "/config/apps/getWeather.py", line 254, in processWeather
    self.high_temp_ent.set_state(fTemperature)
  File "/usr/lib/python3.11/site-packages/appdaemon/utils.py", line 231, in inner_sync_wrapper
    f = run_coroutine_threadsafe(self, coro(self, *args, **kwargs))
                                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: Entity.set_state() takes 1 positional argument but 2 were given
2025-01-20 08:15:00.009100 WARNING GetWeather: ------------------------------------------------------------

Relevant code in the app or config file that caused the issue

sTemperature  = self.temperature_ent.get_state()
    fTemperature  = float(sTemperature)

    if float(self.high_temp_ent.get_state()) < fTemperature:
      self.high_temp_ent.set_state(fTemperature)

Anything else?

No response

@Mike-Allen Mike-Allen added the bug Something isn't working label Jan 21, 2025
@acockburn
Copy link
Member

acockburn commented Jan 23, 2025 via email

@jsl12 jsl12 added the work_in_progress Isse or PR that is evolving and shouldn't;t be aged out label Jan 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working work_in_progress Isse or PR that is evolving and shouldn't;t be aged out
Projects
None yet
Development

No branches or pull requests

3 participants