Added velbus counter sensors, updated to py-velbus 2.0.20 (#16683)

This commit is contained in:
Maikel Punie 2018-09-18 15:51:22 +02:00 committed by Fabian Affolter
parent 1913d07c39
commit 8e7f783da8
3 changed files with 10 additions and 12 deletions

View File

@ -6,8 +6,6 @@ https://home-assistant.io/components/sensor.velbus/
""" """
import logging import logging
from homeassistant.const import (
TEMP_CELSIUS, DEVICE_CLASS_TEMPERATURE)
from homeassistant.components.velbus import ( from homeassistant.components.velbus import (
DOMAIN as VELBUS_DOMAIN, VelbusEntity) DOMAIN as VELBUS_DOMAIN, VelbusEntity)
@ -25,24 +23,24 @@ async def async_setup_platform(hass, config, async_add_entities,
for sensor in discovery_info: for sensor in discovery_info:
module = hass.data[VELBUS_DOMAIN].get_module(sensor[0]) module = hass.data[VELBUS_DOMAIN].get_module(sensor[0])
channel = sensor[1] channel = sensor[1]
sensors.append(VelbusTempSensor(module, channel)) sensors.append(VelbusSensor(module, channel))
async_add_entities(sensors) async_add_entities(sensors)
class VelbusTempSensor(VelbusEntity): class VelbusSensor(VelbusEntity):
"""Representation of a temperature sensor.""" """Representation of a sensor."""
@property @property
def device_class(self): def device_class(self):
"""Return the device class of the sensor.""" """Return the device class of the sensor."""
return DEVICE_CLASS_TEMPERATURE return self._module.get_class(self._channel)
@property @property
def state(self): def state(self):
"""Return the state of the sensor.""" """Return the state of the sensor."""
return self._module.getCurTemp() return self._module.get_state(self._channel)
@property @property
def unit_of_measurement(self): def unit_of_measurement(self):
"""Return the unit this state is expressed in.""" """Return the unit this state is expressed in."""
return TEMP_CELSIUS return self._module.get_unit(self._channel)

View File

@ -12,7 +12,7 @@ from homeassistant.const import EVENT_HOMEASSISTANT_STOP, CONF_PORT
from homeassistant.helpers.discovery import load_platform from homeassistant.helpers.discovery import load_platform
from homeassistant.helpers.entity import Entity from homeassistant.helpers.entity import Entity
REQUIREMENTS = ['python-velbus==2.0.19'] REQUIREMENTS = ['python-velbus==2.0.20']
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)
@ -48,7 +48,7 @@ async def async_setup(hass, config):
discovery_info = { discovery_info = {
'switch': [], 'switch': [],
'binary_sensor': [], 'binary_sensor': [],
'temp_sensor': [] 'sensor': []
} }
for module in modules: for module in modules:
for channel in range(1, module.number_of_channels() + 1): for channel in range(1, module.number_of_channels() + 1):
@ -63,7 +63,7 @@ async def async_setup(hass, config):
load_platform(hass, 'binary_sensor', DOMAIN, load_platform(hass, 'binary_sensor', DOMAIN,
discovery_info['binary_sensor'], config) discovery_info['binary_sensor'], config)
load_platform(hass, 'sensor', DOMAIN, load_platform(hass, 'sensor', DOMAIN,
discovery_info['temp_sensor'], config) discovery_info['sensor'], config)
controller.scan(callback) controller.scan(callback)

View File

@ -1161,7 +1161,7 @@ python-telegram-bot==11.0.0
python-twitch-client==0.6.0 python-twitch-client==0.6.0
# homeassistant.components.velbus # homeassistant.components.velbus
python-velbus==2.0.19 python-velbus==2.0.20
# homeassistant.components.media_player.vlc # homeassistant.components.media_player.vlc
python-vlc==1.1.2 python-vlc==1.1.2