joshendriks / pimatic-bh1750

Pimatic support for the bh1750 light intensity sensor
Apache License 2.0
0 stars 3 forks source link

Change sensor type from temperature to something else #6

Closed kanedo closed 8 years ago

kanedo commented 8 years ago

Hey first: the plugin itself works really great, thanks! I have an issue with it though. I use pimatic-hap to add pimatic as a homekit accessory and it automatically populates all sensors which inherit from the temperature sensor class. unfortunately yours does so as well and causes errors because it does not implement getTemperature

A uncaught exception occured: TypeError: device.getTemperature is not a function

Is there a way of changing this behaviour?

circuitdb commented 8 years ago

The BH1750Sensor does not inherit from the TemperatureSensor class. It inherits from LightIntensitySensor which inherits from Sensor. However the 'template' property (for displaying only) of BH1750Sensor is set to temperature.

Pimatic-hap does not use class types. It uses the 'template' property of a device to determine the device type. According to the pimatic docs (https://pimatic.org/api/actions/) the template is to be used for displaying purposes:

template (string) : Name of the template, that should be used to display the device.

I think that pimatic-hap should use instanceof to determine sensor types as templates are intended for display purposes only.

kanedo commented 8 years ago

Ah I see. Thanks. I guess there is no other template that could be used instead of temperature, right?

There is however a way to disable a device to be used in pimatic hap by adding

"hap": {
      "exclude": true
    }

to the device config. This results in an error on startup though but at least it removes the sensor.

circuitdb commented 8 years ago

That would not fix the issue and would probably break the way the lightintensity is shown.

See the mapping used in pimatic-hap below. I think there is no alternative that would make pimatic-hap call getLightintensity

    knownDevices: {
      'dimmer': DimmerAccessory
      'switch': PowerSwitchAccessory
      'shutter': ShutterAccessory
      'temperature': TemperatureAccessory
      'contact': ContactAccessory
      'thermostat': ThermostatAccessory
      'led-light': LedLightAccessory
      'presence': MotionAccessory
    }
circuitdb commented 8 years ago

I think I'll create a pull request for pimatic to have a LightIntensitySensor including it's own template or so. That woul make it possible to support it in pimatic-hap

kanedo commented 8 years ago

Thank you. I did just tried and changed the template to device which produced the same output in my configuration but having a special template for this would be the nicest way to solve this.