Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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',
'sensor', 'switch', 'scene']
Comment thread
pbalogh77 marked this conversation as resolved.
Outdated

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 = room_name + ' ' + device.name
Comment thread
pbalogh77 marked this conversation as resolved.
Outdated
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
39 changes: 39 additions & 0 deletions homeassistant/components/scene/fibaro.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
"""
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 (
Comment thread
pbalogh77 marked this conversation as resolved.
Scene)
from homeassistant.components.fibaro import (
FIBARO_CONTROLLER, FIBARO_DEVICES, FibaroDevice)

DEPENDENCIES = ['fibaro']

_LOGGER = logging.getLogger(__name__)


def setup_platform(hass, config, add_entities, discovery_info=None):
Comment thread
pbalogh77 marked this conversation as resolved.
Outdated
"""Perform the setup for Fibaro scenes."""
if discovery_info is None:
return

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


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

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

@property
def name(self):
"""Return the name of the scene."""
return self._name