Netatmo Sensor: Implement device_class (#14634)

added device_class and removed icon for temperature and humidity.
This commit is contained in:
Michael Nosthoff 2018-05-30 16:53:35 +02:00 committed by Paulus Schoutsen
parent f1f4d80f24
commit c14e41f431

View File

@ -10,7 +10,9 @@ from datetime import timedelta
import voluptuous as vol import voluptuous as vol
from homeassistant.components.sensor import PLATFORM_SCHEMA from homeassistant.components.sensor import PLATFORM_SCHEMA
from homeassistant.const import TEMP_CELSIUS, STATE_UNKNOWN from homeassistant.const import (
TEMP_CELSIUS, DEVICE_CLASS_HUMIDITY, DEVICE_CLASS_TEMPERATURE,
STATE_UNKNOWN)
from homeassistant.helpers.entity import Entity from homeassistant.helpers.entity import Entity
from homeassistant.util import Throttle from homeassistant.util import Throttle
import homeassistant.helpers.config_validation as cv import homeassistant.helpers.config_validation as cv
@ -26,28 +28,29 @@ DEPENDENCIES = ['netatmo']
MIN_TIME_BETWEEN_UPDATES = timedelta(seconds=600) MIN_TIME_BETWEEN_UPDATES = timedelta(seconds=600)
SENSOR_TYPES = { SENSOR_TYPES = {
'temperature': ['Temperature', TEMP_CELSIUS, 'mdi:thermometer'], 'temperature': ['Temperature', TEMP_CELSIUS, None,
'co2': ['CO2', 'ppm', 'mdi:cloud'], DEVICE_CLASS_TEMPERATURE],
'pressure': ['Pressure', 'mbar', 'mdi:gauge'], 'co2': ['CO2', 'ppm', 'mdi:cloud', None],
'noise': ['Noise', 'dB', 'mdi:volume-high'], 'pressure': ['Pressure', 'mbar', 'mdi:gauge', None],
'humidity': ['Humidity', '%', 'mdi:water-percent'], 'noise': ['Noise', 'dB', 'mdi:volume-high', None],
'rain': ['Rain', 'mm', 'mdi:weather-rainy'], 'humidity': ['Humidity', '%', None, DEVICE_CLASS_HUMIDITY],
'sum_rain_1': ['sum_rain_1', 'mm', 'mdi:weather-rainy'], 'rain': ['Rain', 'mm', 'mdi:weather-rainy', None],
'sum_rain_24': ['sum_rain_24', 'mm', 'mdi:weather-rainy'], 'sum_rain_1': ['sum_rain_1', 'mm', 'mdi:weather-rainy', None],
'battery_vp': ['Battery', '', 'mdi:battery'], 'sum_rain_24': ['sum_rain_24', 'mm', 'mdi:weather-rainy', None],
'battery_lvl': ['Battery_lvl', '', 'mdi:battery'], 'battery_vp': ['Battery', '', 'mdi:battery', None],
'min_temp': ['Min Temp.', TEMP_CELSIUS, 'mdi:thermometer'], 'battery_lvl': ['Battery_lvl', '', 'mdi:battery', None],
'max_temp': ['Max Temp.', TEMP_CELSIUS, 'mdi:thermometer'], 'min_temp': ['Min Temp.', TEMP_CELSIUS, 'mdi:thermometer', None],
'windangle': ['Angle', '', 'mdi:compass'], 'max_temp': ['Max Temp.', TEMP_CELSIUS, 'mdi:thermometer', None],
'windangle_value': ['Angle Value', 'º', 'mdi:compass'], 'windangle': ['Angle', '', 'mdi:compass', None],
'windstrength': ['Strength', 'km/h', 'mdi:weather-windy'], 'windangle_value': ['Angle Value', 'º', 'mdi:compass', None],
'gustangle': ['Gust Angle', '', 'mdi:compass'], 'windstrength': ['Strength', 'km/h', 'mdi:weather-windy', None],
'gustangle_value': ['Gust Angle Value', 'º', 'mdi:compass'], 'gustangle': ['Gust Angle', '', 'mdi:compass', None],
'guststrength': ['Gust Strength', 'km/h', 'mdi:weather-windy'], 'gustangle_value': ['Gust Angle Value', 'º', 'mdi:compass', None],
'rf_status': ['Radio', '', 'mdi:signal'], 'guststrength': ['Gust Strength', 'km/h', 'mdi:weather-windy', None],
'rf_status_lvl': ['Radio_lvl', '', 'mdi:signal'], 'rf_status': ['Radio', '', 'mdi:signal', None],
'wifi_status': ['Wifi', '', 'mdi:wifi'], 'rf_status_lvl': ['Radio_lvl', '', 'mdi:signal', None],
'wifi_status_lvl': ['Wifi_lvl', 'dBm', 'mdi:wifi'] 'wifi_status': ['Wifi', '', 'mdi:wifi', None],
'wifi_status_lvl': ['Wifi_lvl', 'dBm', 'mdi:wifi', None]
} }
MODULE_SCHEMA = vol.Schema({ MODULE_SCHEMA = vol.Schema({
@ -106,7 +109,9 @@ class NetAtmoSensor(Entity):
self.module_name = module_name self.module_name = module_name
self.type = sensor_type self.type = sensor_type
self._state = None self._state = None
self._unit_of_measurement = SENSOR_TYPES[sensor_type][1] self._device_class = SENSOR_TYPES[self.type][3]
self._icon = SENSOR_TYPES[self.type][2]
self._unit_of_measurement = SENSOR_TYPES[self.type][1]
module_id = self.netatmo_data.\ module_id = self.netatmo_data.\
station_data.moduleByName(module=module_name)['_id'] station_data.moduleByName(module=module_name)['_id']
self.module_id = module_id[1] self.module_id = module_id[1]
@ -119,7 +124,12 @@ class NetAtmoSensor(Entity):
@property @property
def icon(self): def icon(self):
"""Icon to use in the frontend, if any.""" """Icon to use in the frontend, if any."""
return SENSOR_TYPES[self.type][2] return self._icon
@property
def device_class(self):
"""Return the device class of the sensor."""
return self._device_class
@property @property
def state(self): def state(self):