From 1fa895f7c1f8c60a09f06916723ac3a0feabb3b0 Mon Sep 17 00:00:00 2001 From: Assaf Inbal Date: Thu, 2 Mar 2017 22:56:46 +0200 Subject: [PATCH] Renamed sensor_class to device_class (#125) The sensor_class attribute was renamed in Home Assistant to device_class. Update name here as well. --- README.md | 4 ++-- accessories/binary_sensor.js | 8 ++++---- index.js | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index e200e2d..4217770 100755 --- a/README.md +++ b/README.md @@ -31,9 +31,9 @@ Here's a list of the devices that are currently exposed: ### Binary Sensor Support -Binary Sensors must have a `sensor_class` set. Accepted `sensor_class`es are `moisture`, `motion`, `occupancy`, `opening` and `smoke`. +Binary Sensors must have a `device_class` set. Accepted `device_class`es are `moisture`, `motion`, `occupancy`, `opening` and `smoke`. -For binary sensors with the `opening` `sensor_class` you can also set `homebridge_opening_type` to `window` to have the entity display as a window instead of a door to Homebridge. +For binary sensors with the `opening` `device_class` you can also set `homebridge_opening_type` to `window` to have the entity display as a window instead of a door to Homebridge. ### Cover Support diff --git a/accessories/binary_sensor.js b/accessories/binary_sensor.js index 422239a..5af0c8e 100644 --- a/accessories/binary_sensor.js +++ b/accessories/binary_sensor.js @@ -59,7 +59,7 @@ class HomeAssistantBinarySensor { informationService .setCharacteristic(Characteristic.Manufacturer, 'Home Assistant') - .setCharacteristic(Characteristic.Model, `${toTitleCase(this.data.attributes.sensor_class)} Binary Sensor`) + .setCharacteristic(Characteristic.Model, `${toTitleCase(this.data.attributes.device_class)} Binary Sensor`) .setCharacteristic(Characteristic.SerialNumber, this.entity_id); return [informationService, this.sensorService]; @@ -67,10 +67,10 @@ class HomeAssistantBinarySensor { } function HomeAssistantBinarySensorFactory(log, data, client) { - if (!(data.attributes && data.attributes.sensor_class)) { + if (!(data.attributes && data.attributes.device_class)) { return null; } - switch (data.attributes.sensor_class) { + switch (data.attributes.device_class) { case 'moisture': return new HomeAssistantBinarySensor(log, data, client, Service.LeakSensor, @@ -102,7 +102,7 @@ function HomeAssistantBinarySensorFactory(log, data, client) { Characteristic.SmokeDetected.SMOKE_DETECTED, Characteristic.SmokeDetected.SMOKE_NOT_DETECTED); default: - log.error(`'${data.entity_id}' has a sensor_class of '${data.attributes.sensor_class}' which is not supported by ` + + log.error(`'${data.entity_id}' has a device_class of '${data.attributes.device_class}' which is not supported by ` + 'homebridge-homeassistant. Supported classes are \'moisture\', \'motion\', \'occupancy\', \'opening\' and \'smoke\'. ' + 'See the README.md for more information.'); return null; diff --git a/index.js b/index.js index 628ce9b..70327df 100644 --- a/index.js +++ b/index.js @@ -177,7 +177,7 @@ HomeAssistantPlatform.prototype = { accessory = HomeAssistantDeviceTrackerFactory(that.log, entity, that); } else if (entityType === 'media_player' && entity.attributes && entity.attributes.supported_features) { accessory = new HomeAssistantMediaPlayer(that.log, entity, that); - } else if (entityType === 'binary_sensor' && entity.attributes && entity.attributes.sensor_class) { + } else if (entityType === 'binary_sensor' && entity.attributes && entity.attributes.device_class) { accessory = HomeAssistantBinarySensorFactory(that.log, entity, that); }