mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 05:07:41 +00:00
Velbus: autodiscover covers (#24877)
* Added covers to the velbus component with autodicovery, bumped python velbus version * Fixed some pylint stuff
This commit is contained in:
parent
5cf923ead6
commit
bf70e91a0d
@ -38,6 +38,7 @@ async def async_setup(hass, config):
|
|||||||
def callback():
|
def callback():
|
||||||
modules = controller.get_modules()
|
modules = controller.get_modules()
|
||||||
discovery_info = {
|
discovery_info = {
|
||||||
|
'cover': [],
|
||||||
'switch': [],
|
'switch': [],
|
||||||
'binary_sensor': [],
|
'binary_sensor': [],
|
||||||
'climate': [],
|
'climate': [],
|
||||||
@ -59,6 +60,8 @@ async def async_setup(hass, config):
|
|||||||
discovery_info['binary_sensor'], config)
|
discovery_info['binary_sensor'], config)
|
||||||
load_platform(hass, 'sensor', DOMAIN,
|
load_platform(hass, 'sensor', DOMAIN,
|
||||||
discovery_info['sensor'], config)
|
discovery_info['sensor'], config)
|
||||||
|
load_platform(hass, 'cover', DOMAIN,
|
||||||
|
discovery_info['cover'], config)
|
||||||
|
|
||||||
def syn_clock(self, service=None):
|
def syn_clock(self, service=None):
|
||||||
controller.sync_clock()
|
controller.sync_clock()
|
||||||
|
@ -1,151 +1,60 @@
|
|||||||
"""Support for Velbus covers."""
|
"""Support for Velbus covers."""
|
||||||
import logging
|
import logging
|
||||||
import time
|
|
||||||
|
|
||||||
import voluptuous as vol
|
|
||||||
|
|
||||||
from homeassistant.components.cover import (
|
from homeassistant.components.cover import (
|
||||||
PLATFORM_SCHEMA, SUPPORT_CLOSE, SUPPORT_OPEN, SUPPORT_STOP, CoverDevice)
|
CoverDevice, SUPPORT_CLOSE, SUPPORT_OPEN, SUPPORT_STOP)
|
||||||
from homeassistant.const import CONF_COVERS, CONF_NAME
|
|
||||||
import homeassistant.helpers.config_validation as cv
|
|
||||||
|
|
||||||
from . import DOMAIN
|
from . import DOMAIN as VELBUS_DOMAIN, VelbusEntity
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
COVER_SCHEMA = vol.Schema({
|
|
||||||
vol.Required('module'): cv.positive_int,
|
|
||||||
vol.Required('open_channel'): cv.positive_int,
|
|
||||||
vol.Required('close_channel'): cv.positive_int,
|
|
||||||
vol.Required(CONF_NAME): cv.string
|
|
||||||
})
|
|
||||||
|
|
||||||
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
|
async def async_setup_platform(
|
||||||
vol.Required(CONF_COVERS): cv.schema_with_slug_keys(COVER_SCHEMA),
|
hass, config, async_add_entities, discovery_info=None):
|
||||||
})
|
"""Set up the Velbus xover platform."""
|
||||||
|
if discovery_info is None:
|
||||||
|
return
|
||||||
def setup_platform(hass, config, add_entities, discovery_info=None):
|
|
||||||
"""Set up cover controlled by Velbus."""
|
|
||||||
devices = config.get(CONF_COVERS, {})
|
|
||||||
covers = []
|
covers = []
|
||||||
|
for cover in discovery_info:
|
||||||
velbus = hass.data[DOMAIN]
|
module = hass.data[VELBUS_DOMAIN].get_module(cover[0])
|
||||||
for device_name, device_config in devices.items():
|
channel = cover[1]
|
||||||
covers.append(
|
covers.append(VelbusCover(module, channel))
|
||||||
VelbusCover(
|
async_add_entities(covers)
|
||||||
velbus,
|
|
||||||
device_config.get(CONF_NAME, device_name),
|
|
||||||
device_config.get('module'),
|
|
||||||
device_config.get('open_channel'),
|
|
||||||
device_config.get('close_channel')
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
if not covers:
|
|
||||||
_LOGGER.error("No covers added")
|
|
||||||
return False
|
|
||||||
|
|
||||||
add_entities(covers)
|
|
||||||
|
|
||||||
|
|
||||||
class VelbusCover(CoverDevice):
|
class VelbusCover(VelbusEntity, CoverDevice):
|
||||||
"""Representation a Velbus cover."""
|
"""Representation a Velbus cover."""
|
||||||
|
|
||||||
def __init__(self, velbus, name, module, open_channel, close_channel):
|
|
||||||
"""Initialize the cover."""
|
|
||||||
self._velbus = velbus
|
|
||||||
self._name = name
|
|
||||||
self._close_channel_state = None
|
|
||||||
self._open_channel_state = None
|
|
||||||
self._module = module
|
|
||||||
self._open_channel = open_channel
|
|
||||||
self._close_channel = close_channel
|
|
||||||
|
|
||||||
async def async_added_to_hass(self):
|
|
||||||
"""Add listener for Velbus messages on bus."""
|
|
||||||
def _init_velbus():
|
|
||||||
"""Initialize Velbus on startup."""
|
|
||||||
self._velbus.subscribe(self._on_message)
|
|
||||||
self.get_status()
|
|
||||||
|
|
||||||
await self.hass.async_add_job(_init_velbus)
|
|
||||||
|
|
||||||
def _on_message(self, message):
|
|
||||||
import velbus
|
|
||||||
if isinstance(message, velbus.RelayStatusMessage):
|
|
||||||
if message.address == self._module:
|
|
||||||
if message.channel == self._close_channel:
|
|
||||||
self._close_channel_state = message.is_on()
|
|
||||||
self.schedule_update_ha_state()
|
|
||||||
if message.channel == self._open_channel:
|
|
||||||
self._open_channel_state = message.is_on()
|
|
||||||
self.schedule_update_ha_state()
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def supported_features(self):
|
def supported_features(self):
|
||||||
"""Flag supported features."""
|
"""Flag supported features."""
|
||||||
return SUPPORT_OPEN | SUPPORT_CLOSE | SUPPORT_STOP
|
return SUPPORT_OPEN | SUPPORT_CLOSE | SUPPORT_STOP
|
||||||
|
|
||||||
@property
|
|
||||||
def should_poll(self):
|
|
||||||
"""Disable polling."""
|
|
||||||
return False
|
|
||||||
|
|
||||||
@property
|
|
||||||
def name(self):
|
|
||||||
"""Return the name of the cover."""
|
|
||||||
return self._name
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def is_closed(self):
|
def is_closed(self):
|
||||||
"""Return if the cover is closed."""
|
"""Return if the cover is closed."""
|
||||||
return self._close_channel_state
|
return self._module.is_closed(self._channel)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def current_cover_position(self):
|
def current_cover_position(self):
|
||||||
"""Return current position of cover.
|
"""Return current position of cover.
|
||||||
|
|
||||||
None is unknown.
|
None is unknown, 0 is closed, 100 is fully open
|
||||||
"""
|
"""
|
||||||
|
if self._module.is_closed(self._channel):
|
||||||
|
return 0
|
||||||
|
if self._module.is_open(self._channel):
|
||||||
|
return 100
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def _relay_off(self, channel):
|
|
||||||
import velbus
|
|
||||||
message = velbus.SwitchRelayOffMessage()
|
|
||||||
message.set_defaults(self._module)
|
|
||||||
message.relay_channels = [channel]
|
|
||||||
self._velbus.send(message)
|
|
||||||
|
|
||||||
def _relay_on(self, channel):
|
|
||||||
import velbus
|
|
||||||
message = velbus.SwitchRelayOnMessage()
|
|
||||||
message.set_defaults(self._module)
|
|
||||||
message.relay_channels = [channel]
|
|
||||||
self._velbus.send(message)
|
|
||||||
|
|
||||||
def open_cover(self, **kwargs):
|
def open_cover(self, **kwargs):
|
||||||
"""Open the cover."""
|
"""Open the cover."""
|
||||||
self._relay_off(self._close_channel)
|
self._module.open(self._channel)
|
||||||
time.sleep(0.3)
|
|
||||||
self._relay_on(self._open_channel)
|
|
||||||
|
|
||||||
def close_cover(self, **kwargs):
|
def close_cover(self, **kwargs):
|
||||||
"""Close the cover."""
|
"""Close the cover."""
|
||||||
self._relay_off(self._open_channel)
|
self._module.close(self._channel)
|
||||||
time.sleep(0.3)
|
|
||||||
self._relay_on(self._close_channel)
|
|
||||||
|
|
||||||
def stop_cover(self, **kwargs):
|
def stop_cover(self, **kwargs):
|
||||||
"""Stop the cover."""
|
"""Stop the cover."""
|
||||||
self._relay_off(self._open_channel)
|
self._module.stop(self._channel)
|
||||||
time.sleep(0.3)
|
|
||||||
self._relay_off(self._close_channel)
|
|
||||||
|
|
||||||
def get_status(self):
|
|
||||||
"""Retrieve current status."""
|
|
||||||
import velbus
|
|
||||||
message = velbus.ModuleStatusRequestMessage()
|
|
||||||
message.set_defaults(self._module)
|
|
||||||
message.channels = [self._open_channel, self._close_channel]
|
|
||||||
self._velbus.send(message)
|
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
"name": "Velbus",
|
"name": "Velbus",
|
||||||
"documentation": "https://www.home-assistant.io/components/velbus",
|
"documentation": "https://www.home-assistant.io/components/velbus",
|
||||||
"requirements": [
|
"requirements": [
|
||||||
"python-velbus==2.0.26"
|
"python-velbus==2.0.27"
|
||||||
],
|
],
|
||||||
"dependencies": [],
|
"dependencies": [],
|
||||||
"codeowners": []
|
"codeowners": []
|
||||||
|
@ -1487,7 +1487,7 @@ python-telnet-vlc==1.0.4
|
|||||||
python-twitch-client==0.6.0
|
python-twitch-client==0.6.0
|
||||||
|
|
||||||
# homeassistant.components.velbus
|
# homeassistant.components.velbus
|
||||||
python-velbus==2.0.26
|
python-velbus==2.0.27
|
||||||
|
|
||||||
# homeassistant.components.vlc
|
# homeassistant.components.vlc
|
||||||
python-vlc==1.1.2
|
python-vlc==1.1.2
|
||||||
|
Loading…
x
Reference in New Issue
Block a user