Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial scene support for Fibaro hubs #18779

Merged
merged 9 commits into from
Dec 3, 2018
21 changes: 20 additions & 1 deletion homeassistant/components/fibaro.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
ATTR_CURRENT_ENERGY_KWH = "current_energy_kwh"
CONF_PLUGINS = "plugins"

FIBARO_COMPONENTS = ['binary_sensor', 'cover', 'light', 'sensor', 'switch']
FIBARO_COMPONENTS = ['binary_sensor', 'cover', 'light',
'scene', 'sensor', 'switch']

FIBARO_TYPEMAP = {
'com.fibaro.multilevelSensor': "sensor",
Expand Down Expand Up @@ -71,6 +72,7 @@ def __init__(self, username, password, url, import_plugins):
"""Initialize the Fibaro controller."""
from fiblary3.client.v4.client import Client as FibaroClient
self._client = FibaroClient(url, username, password)
self._scene_map = None

def connect(self):
"""Start the communication with the Fibaro controller."""
Expand All @@ -87,6 +89,7 @@ def connect(self):

self._room_map = {room.id: room for room in self._client.rooms.list()}
self._read_devices()
self._read_scenes()
return True

def enable_state_handler(self):
Expand Down Expand Up @@ -166,6 +169,22 @@ def _map_device_to_type(device):
device_type = 'light'
return device_type

def _read_scenes(self):
scenes = self._client.scenes.list()
self._scene_map = {}
for device in scenes:
if not device.visible:
continue
if device.roomID == 0:
room_name = 'Unknown'
else:
room_name = self._room_map[device.roomID].name
device.friendly_name = '{} {}'.format(room_name, device.name)
device.ha_id = '{}_{}_{}'.format(
slugify(room_name), slugify(device.name), device.id)
self._scene_map[device.id] = device
self.fibaro_devices['scene'].append(device)

def _read_devices(self):
"""Read and process the device list."""
devices = self._client.devices.list()
Expand Down
35 changes: 35 additions & 0 deletions homeassistant/components/scene/fibaro.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
"""
Support for Fibaro scenes.

For more details about this platform, please refer to the documentation at
https://home-assistant.io/components/scene.fibaro/
"""
import logging

from homeassistant.components.scene import (
pbalogh77 marked this conversation as resolved.
Show resolved Hide resolved
Scene)
from homeassistant.components.fibaro import (
FIBARO_CONTROLLER, FIBARO_DEVICES, FibaroDevice)

DEPENDENCIES = ['fibaro']

_LOGGER = logging.getLogger(__name__)


async def async_setup_platform(hass, config, async_add_entities,
discovery_info=None):
"""Perform the setup for Fibaro scenes."""
if discovery_info is None:
return

async_add_entities(
[FibaroScene(scene, hass.data[FIBARO_CONTROLLER])
for scene in hass.data[FIBARO_DEVICES]['scene']], True)


class FibaroScene(FibaroDevice, Scene):
pbalogh77 marked this conversation as resolved.
Show resolved Hide resolved
"""Representation of a Fibaro scene entity."""

async def async_activate(self):
pbalogh77 marked this conversation as resolved.
Show resolved Hide resolved
"""Activate the scene."""
self.fibaro_device.start()
pbalogh77 marked this conversation as resolved.
Show resolved Hide resolved