WebThingsIO / gateway-addon-python

Python bindings for developing add-ons for WebThings Gateway
Mozilla Public License 2.0
16 stars 10 forks source link

Name stays undefined #54

Closed flatsiedatsie closed 5 years ago

flatsiedatsie commented 5 years ago

I must be doing something wrong, but in the 0.9 beta I can't get any thing names to show up.

    def __init__(self, adapter, _id, sketch_name):
        """
        Initialize the object.

        adapter -- the Adapter managing this device
        _id -- ID of this device
        sketch_name -- The MySensors node name
        index -- index inside parent device
        """

        #self._id = "MySensors_" + str(_id)
        self._id = 'MySensors-{}'.format(_id)   # was self._id = 'MySensors-{}'.format(_id)

        print("Device init, sketch name: " + str(sketch_name))
        print("_id: " + str(_id))
        Device.__init__(self, adapter, _id)

        self.adapter = adapter
        self.id = self._id #"MySensors-" + str(_id)
        #self._id = str(_id)
        self.name = str(sketch_name)
        self.title = str(sketch_name)
        self.description = str(sketch_name)

        self._type = [] # TODO: isn't this deprecated?
        self.properties = {}
        #print("device self.properties at init: " + str(self.properties))
        self.connected = False # Will be set to true once we receive an actual message from the node. # TODO: is this still used?

        print("name = " + str(self.name))
        print("title = " + str(self.title))
        print("as_dict = " + str(self.as_dict()))

This leads to:

Device init, sketch name: Temperature sensor
_id: 36
name = Temperature sensor
title = Temperature sensor
as_dict = {'id': 'MySensors-36', 'name': 'Temperature sensor', 'type': 'thing', '@context': 'https://iot.mozilla.org/schemas', '@type': [], 'description': 'Temperature sensor', 'properties': {}, 'actions': {}, 'events': {}, 'baseHref': None, 'pin': {'required': False, 'pattern': None}, 'credentialsRequired': False}

Even though according to the code the asDict() function should show the title attribute, it doesn't seem to.

flatsiedatsie commented 5 years ago

if I copy the asDict and asThing code into the add-on, then it does work. Which would negate this statement.

mrstegeman commented 5 years ago

Is there a reason you're still copying the as_dict and as_thing methods? If you're testing locally, just install the 0.9 version of gateway_addon from here: https://github.com/mozilla-iot/gateway-addon-python

flatsiedatsie commented 5 years ago

But shouldn't the 0.9 version already be in the 0.9 beta? And if that new code wasn't there yet, then why did it ignore the this.name variable?

How do I install the new version of the gateway addon python into my system?

mrstegeman commented 5 years ago

Are you talking about the build from this thread? https://github.com/mozilla-iot/gateway/issues/1965

I forgot that existed.

sudo pip3 install git+https://github.com/mozilla-iot/gateway-addon-python.git

flatsiedatsie commented 5 years ago

Yes, that's the build I'm talking about.

mrstegeman commented 5 years ago

Please try the updated gateway-addon library and let me know if you still have issues.

flatsiedatsie commented 5 years ago

There was an erorr with the adapt parser version?

But it says it was successful anyway.

pi@gateway:~$ sudo pip3 install git+https://github.com/mozilla-iot/gateway-addon-python.git
Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple
Collecting git+https://github.com/mozilla-iot/gateway-addon-python.git
  Cloning https://github.com/mozilla-iot/gateway-addon-python.git to /tmp/pip-req-build-4iia9or1
Requirement already satisfied: jsonschema>=3.0.0 in /usr/local/lib/python3.7/dist-packages (from gateway-addon==0.9.0) (3.0.1)
Requirement already satisfied: nnpy==1.4.2 in /usr/local/lib/python3.7/dist-packages (from gateway-addon==0.9.0) (1.4.2)
Collecting six>=1.11.0 (from jsonschema>=3.0.0->gateway-addon==0.9.0)
  Downloading https://files.pythonhosted.org/packages/73/fb/00a976f728d0d1fecfe898238ce23f502a721c0ac0ecfedb80e0d88c64e9/six-1.12.0-py2.py3-none-any.whl
Requirement already satisfied: attrs>=17.4.0 in /usr/local/lib/python3.7/dist-packages (from jsonschema>=3.0.0->gateway-addon==0.9.0) (19.1.0)
Requirement already satisfied: pyrsistent>=0.14.0 in /usr/local/lib/python3.7/dist-packages (from jsonschema>=3.0.0->gateway-addon==0.9.0) (0.15.2)
Requirement already satisfied: setuptools in /usr/lib/python3/dist-packages (from jsonschema>=3.0.0->gateway-addon==0.9.0) (40.8.0)
Requirement already satisfied: cffi in /usr/local/lib/python3.7/dist-packages (from nnpy==1.4.2->gateway-addon==0.9.0) (1.12.3)
Requirement already satisfied: pycparser in /usr/local/lib/python3.7/dist-packages (from cffi->nnpy==1.4.2->gateway-addon==0.9.0) (2.19)
Building wheels for collected packages: gateway-addon
  Running setup.py bdist_wheel for gateway-addon ... done
  Stored in directory: /tmp/pip-ephem-wheel-cache-qzst4fjn/wheels/7f/68/13/73d8ea6b8c75f67073720fc8697c7f8640d1d03038b5f40a5f
Successfully built gateway-addon
adapt-parser 0.3.3 has requirement six==1.10.0, but you'll have six 1.12.0 which is incompatible.
Installing collected packages: gateway-addon, six
  Found existing installation: gateway-addon 0.8.0
    Uninstalling gateway-addon-0.8.0:
      Successfully uninstalled gateway-addon-0.8.0
  Found existing installation: six 1.10.0
    Uninstalling six-1.10.0:
      Successfully uninstalled six-1.10.0
Successfully installed gateway-addon-0.9.0 six-1.12.0
flatsiedatsie commented 5 years ago

It seems to work!

mrstegeman commented 5 years ago

We've resolved that adapt issue upstream, but you should should have no issues in the current state either.

Glad things are working for you now!

flatsiedatsie commented 5 years ago

The temperature value still shows no decimals, but that's probably not this issue.

mrstegeman commented 5 years ago

Correct, that will require an updated UI.