Skip to content
Merged
25 changes: 21 additions & 4 deletions homeassistant/components/velux/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

from homeassistant.helpers import discovery
import homeassistant.helpers.config_validation as cv
from homeassistant.const import CONF_HOST, CONF_PASSWORD
from homeassistant.const import (CONF_HOST, CONF_PASSWORD, EVENT_HOMEASSISTANT_STOP)

DOMAIN = "velux"
DATA_VELUX = "data_velux"
Expand All @@ -28,6 +28,7 @@ async def async_setup(hass, config):

try:
hass.data[DATA_VELUX] = VeluxModule(hass, config)
Comment thread
MartinHjelmare marked this conversation as resolved.
Outdated
hass.data[DATA_VELUX].setup()
await hass.data[DATA_VELUX].async_start()

except PyVLXException as ex:
Expand All @@ -46,13 +47,29 @@ class VeluxModule:

def __init__(self, hass, config):
"""Initialize for velux component."""
from pyvlx import PyVLX
self._hass = hass
self._config = config

Comment thread
MartinHjelmare marked this conversation as resolved.
Outdated

host = config[DOMAIN].get(CONF_HOST)
password = config[DOMAIN].get(CONF_PASSWORD)
def setup(self):
async def on_hass_stop(event):
"""Close connection when hass stops."""
_LOGGER.info("Velux interface terminated")
Comment thread
MartinHjelmare marked this conversation as resolved.
Outdated
await self.pyvlx.disconnect()

self._hass.bus.async_listen_once(EVENT_HOMEASSISTANT_STOP, on_hass_stop)
from pyvlx import PyVLX
Comment thread
MartinHjelmare marked this conversation as resolved.
Outdated
host = self._config[DOMAIN].get(CONF_HOST)
Comment thread
MartinHjelmare marked this conversation as resolved.
Outdated
password = self._config[DOMAIN].get(CONF_PASSWORD)
self.pyvlx = PyVLX(host=host, password=password)


async def async_start(self):
"""Start velux component."""
_LOGGER.info("Velux interface started")
Comment thread
MartinHjelmare marked this conversation as resolved.
Outdated
await self.pyvlx.load_scenes()
await self.pyvlx.load_nodes()

for node in self.pyvlx.nodes:
_LOGGER.info("Stopping node: " + str(node))
Comment thread
MartinHjelmare marked this conversation as resolved.
Outdated
await node.stop(wait_for_completion=False)
Comment thread
MartinHjelmare marked this conversation as resolved.
Outdated