cflurin / homebridge-mqtt

Homebridge-mqtt is a Plugin for Homebridge.
Apache License 2.0
229 stars 39 forks source link

STRING characteristic type not handled correctly + Fix Howto #33

Closed ghost closed 7 years ago

ghost commented 7 years ago

Due to the lack of custom characteristics I added an "InputSource" Service and a Source Characteristic in HomeKitTypes.js of HAB_Node as a workaround.

/**
  * Characteristic "Source"
  */

Characteristic.Source = function() {
  Characteristic.call(this, 'Source', '00000001-0000-2000-8000-0026BB765291');
  this.setProps({
    format: Characteristic.Formats.STRING,
    perms: [Characteristic.Perms.READ, Characteristic.Perms.WRITE, Characteristic.Perms.NOTIFY]
  });
  this.value = this.getDefaultValue();
};

inherits(Characteristic.Source, Characteristic);

Characteristic.Source.UUID = '00000001-0000-2000-8000-0026BB765291';
/**
 * Service "InputSource"
 */

Service.InputSource = function(displayName, subtype) {
  Service.call(this, displayName, '00000002-0000-2000-8000-0026BB765291', subtype);

  // Required Characteristics
  this.addCharacteristic(Characteristic.Source);

  // Optional Characteristics
  this.addOptionalCharacteristic(Characteristic.Name);
};

inherits(Service.InputSource, Service);

Service.InputSource.UUID = '00000002-0000-2000-8000-0026BB765291';

I have a python deamon running at the other mqqt end. I had success with two switches (AMP and TV) where I was able to alter the Source of both AMP and TV.

However there was a problem with getting the value into HomeKit over homebridge-mqqt. after enabling some debug statements and starting with "home bridge -D" it turned out to be a simple fix.

in /lib/accessory.js - Accessory.prototype.parseValue

in

switch(sc.props.format)( { // Added by me case "string": break; // End of Fix

in the default: section, change the line // string, tlv8 accordingly.

Helmsman35

cflurin commented 7 years ago

@helmsman35: thanks for your feedback. I've just uploaded a new version (accessory.js). So for now only the new characteristic/service has to be added to HomeKitTypes.js.

ghost commented 7 years ago

Cool, Can you tell me what the Util.getHomeKitTypes is used for? Although added recently, it is never called by anything.

See the "custom characteristic issue discussion"

cflurin commented 7 years ago

Util.getHomeKitType is a small function that returns an array of all services ordered by uuid. I used it for testing purpose. Finally I've found a solution to get the services by uuid (https://github.com/cflurin/homebridge-mqtt/blob/master/lib/accessory.js#L200)