molobrakos / tellduslive

Communicate with Telldus Live servers
The Unlicense
10 stars 9 forks source link

Device ids can collide with sensor ids in Local API #5

Closed rasmusbe closed 6 years ago

rasmusbe commented 6 years ago

If you have a sensor witch sends both sensor data and is a binary sensor (which telldus handles as a device) the binary sensor/device gets overwritten when Session.update().

An example of this is with Aeotec Multisensor 6 which sends motion detection as a state. In the live API the sensor and the device has different ids, but not in the local api.

devices/list in local api:

{
  "device": [
    {
      "id": 18,
      "methods": 0,
      "name": "Balkong",
      "state": 2,
      "statevalue": "",
      "type": "device"
    }
  ]
}

sensors/list in local api:

{
  "sensor": [
    {
      "battery": 100,
      "data": [
        {
          "name": "lum",
          "scale": 1,
          "value": 0.0
        },
        {
          "name": "temp",
          "scale": 0,
          "value": 3.8999999999999999
        },
        {
          "name": "humidity",
          "scale": 0,
          "value": 79.0
        },
        {
          "name": "uv",
          "scale": 0,
          "value": 0.0
        }
      ],
      "id": 18,
      "model": "n/a",
      "name": "Balkong",
      "protocol": "zwave",
      "sensorId": 18
    }
  ]
}
molobrakos commented 6 years ago

Interesting, I guess that was unexpected :-) We could keep devices and sensors in separate namespaces of course, but as a sorts of quick-fix with less risk of regressions, maybe we can just prefix the id:s in the collect method?

molobrakos commented 6 years ago

Like this https://github.com/molobrakos/tellduslive/compare/id-fix

molobrakos commented 6 years ago

Can you please test and see if this change solves the issue with the sensor/device in your setup?

rasmusbe commented 6 years ago

@molobrakos Thanks, just change line 312 to self._state.update({'_' * is_sensor + str(device['id']): device (converting device['id'] to string) and it works!

molobrakos commented 6 years ago

Ah, one more difference then between the two API:s - I only tested against the cloud service, and it returns the id:s as strings.