Giter Club home page Giter Club logo

Comments (5)

acockburn avatar acockburn commented on July 26, 2024

Hi there - this is failing when trying to set the attributes piece - it's not clear from your code what is actually in there - can you explain a little further?

from appdaemon.

boonhapus avatar boonhapus commented on July 26, 2024

Sure, I changed the code a bit, but it's not much of a matter. The new attributes dict has a spot for friendly_name and icon, to expose it to the HASS API. Less work in the long run for my final product. :)

2017-02-04 11:15:05.752874 WARNING ------------------------------------------------------------
2017-02-04 11:15:05.753426 WARNING Unexpected error in worker for App presence_listener:
2017-02-04 11:15:05.754236 WARNING Worker Ags: {'type': 'event', 'kwargs': {}, 'event': 'internal_trigger_ishome', 'function': <bound method PresenceListener.person_is_home of <presence_listener.PresenceListener object at 0x708a9250>>, 'id': UUID('5feaadfb-ade3-4790-875c-8404c08d19ae'), 'data': {'mac': 'a1:11:1a:a1:11:1a', 'last_seen': '2017-02-04 11:15:05'}, 'name': 'presence_listener'}
2017-02-04 11:15:05.754639 WARNING ------------------------------------------------------------
2017-02-04 11:15:05.758652 WARNING Traceback (most recent call last):
  File "/usr/local/lib/python3.4/dist-packages/appdaemon/appdaemon.py", line 458, in worker
    function(args["event"], data, args["kwargs"])
  File "/home/homeassistant/.homeassistant/appdaemon/conf/apps/presence_listener.py", line 91, in person_is_home
    attributes=json.dumps(attributes))
  File "/usr/local/lib/python3.4/dist-packages/appdaemon/appapi.py", line 185, in set_state
    args["attributes"].update(kwargs["attributes"])
ValueError: dictionary update sequence element #0 has length 1; 2 is required

2017-02-04 11:15:05.759490 WARNING ------------------------------------------------------------

And the relevant bit of code is below.
user_name is type str
last_seen is type str in the format %Y-%m-%d %H:%M:%S
mac is type str .. I've altered it above in the error, but the format is there for you to understand.

        # build the attributes for set_state()
        attributes = {
            "user_name": self.users[mac]['friendly_name'],
            "mac": mac,
            "last_seen": last_seen,
            "friendly_name": "Presence",
            "icon": "mdi:home"
        }

        # expose this information to the front end, including the full object
        self.set_state('binary_sensor.{}_presence'.format(self.users[mac]['friendly_name'].lower()),
                       state=self.users[mac]['location'],
                       attributes=json.dumps(attributes))

Let me know if you have more questions

  • SN

from appdaemon.

acockburn avatar acockburn commented on July 26, 2024

I think the issue is you are converting the attributes into JSON - that is not required and is in fact positively harmful. Under the covers in AppDaemon, the attributes dictionary is merged with the state dictionary, then the whole thing is converted to JSON ahead of sending it to HA, so you don't need to worry about JSON at all, just Python constructs.

Can you try it without the JSON conversion and report back?

from appdaemon.

boonhapus avatar boonhapus commented on July 26, 2024

Something something over optimization .... I should trust you more. That solved it!

from appdaemon.

acockburn avatar acockburn commented on July 26, 2024

Hehe, glad you got it working :)_

from appdaemon.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.