From 5d7a2f92df7a17900baadfde426e26ff9fb2aa1e Mon Sep 17 00:00:00 2001 From: Maikel Punie Date: Mon, 27 Aug 2018 06:06:46 +0200 Subject: [PATCH] Add temperature sensors to the velbus component (#16203) * Added support for velbus temperature sensors * Bumped the required version * updated requirements_all.txt * Auto review comments fixed * Updated after comments * Updated after comments * Fix travis * Fix travis --- homeassistant/components/sensor/velbus.py | 48 +++++++++++++++++++++++ homeassistant/components/velbus.py | 7 +++- requirements_all.txt | 2 +- 3 files changed, 54 insertions(+), 3 deletions(-) create mode 100644 homeassistant/components/sensor/velbus.py diff --git a/homeassistant/components/sensor/velbus.py b/homeassistant/components/sensor/velbus.py new file mode 100644 index 00000000000..ea4af320add --- /dev/null +++ b/homeassistant/components/sensor/velbus.py @@ -0,0 +1,48 @@ +""" +Velbus sensors. + +For more details about this platform, please refer to the documentation +https://home-assistant.io/components/sensor.velbus/ +""" +import logging + +from homeassistant.const import ( + TEMP_CELSIUS, DEVICE_CLASS_TEMPERATURE) +from homeassistant.components.velbus import ( + DOMAIN as VELBUS_DOMAIN, VelbusEntity) + +_LOGGER = logging.getLogger(__name__) + +DEPENDENCIES = ['velbus'] + + +async def async_setup_platform(hass, config, async_add_entities, + discovery_info=None): + """Set up the Velbus temp sensor platform.""" + if discovery_info is None: + return + sensors = [] + for sensor in discovery_info: + module = hass.data[VELBUS_DOMAIN].get_module(sensor[0]) + channel = sensor[1] + sensors.append(VelbusTempSensor(module, channel)) + async_add_entities(sensors) + + +class VelbusTempSensor(VelbusEntity): + """Representation of a temperature sensor.""" + + @property + def device_class(self): + """Return the device class of the sensor.""" + return DEVICE_CLASS_TEMPERATURE + + @property + def state(self): + """Return the state of the sensor.""" + return self._module.getCurTemp() + + @property + def unit_of_measurement(self): + """Return the unit this state is expressed in.""" + return TEMP_CELSIUS diff --git a/homeassistant/components/velbus.py b/homeassistant/components/velbus.py index a6cdcc7cf90..d2def6f96bc 100644 --- a/homeassistant/components/velbus.py +++ b/homeassistant/components/velbus.py @@ -12,7 +12,7 @@ from homeassistant.const import EVENT_HOMEASSISTANT_STOP, CONF_PORT from homeassistant.helpers.discovery import load_platform from homeassistant.helpers.entity import Entity -REQUIREMENTS = ['python-velbus==2.0.18'] +REQUIREMENTS = ['python-velbus==2.0.19'] _LOGGER = logging.getLogger(__name__) @@ -47,7 +47,8 @@ async def async_setup(hass, config): modules = controller.get_modules() discovery_info = { 'switch': [], - 'binary_sensor': [] + 'binary_sensor': [], + 'temp_sensor': [] } for module in modules: for channel in range(1, module.number_of_channels() + 1): @@ -61,6 +62,8 @@ async def async_setup(hass, config): discovery_info['switch'], config) load_platform(hass, 'binary_sensor', DOMAIN, discovery_info['binary_sensor'], config) + load_platform(hass, 'sensor', DOMAIN, + discovery_info['temp_sensor'], config) controller.scan(callback) diff --git a/requirements_all.txt b/requirements_all.txt index e1b5b1c70ec..959fd21732f 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -1139,7 +1139,7 @@ python-telegram-bot==10.1.0 python-twitch==1.3.0 # homeassistant.components.velbus -python-velbus==2.0.18 +python-velbus==2.0.19 # homeassistant.components.media_player.vlc python-vlc==1.1.2