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

TelldusLive config flow #18758

Merged
merged 11 commits into from Dec 10, 2018
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
31 changes: 22 additions & 9 deletions homeassistant/components/binary_sensor/tellduslive.py
Expand Up @@ -9,22 +9,35 @@
"""
import logging

from homeassistant.components import tellduslive
from homeassistant.components import binary_sensor, tellduslive
from homeassistant.components.binary_sensor import BinarySensorDevice
from homeassistant.components.tellduslive.entry import TelldusLiveEntity
from homeassistant.helpers.dispatcher import async_dispatcher_connect

_LOGGER = logging.getLogger(__name__)


def setup_platform(hass, config, add_entities, discovery_info=None):
"""Set up Tellstick sensors."""
if discovery_info is None:
return
client = hass.data[tellduslive.DOMAIN]
add_entities(
TelldusLiveSensor(client, binary_sensor)
for binary_sensor in discovery_info
)
"""Old way of setting up TelldusLive.

Can only be called when a user accidentally mentions the platform in their
config. But even in that case it would have been ignored.
"""
pass


async def async_setup_entry(hass, config_entry, async_add_entities):
"""Set up tellduslive sensors dynamically."""
async def async_discover_binary_sensor(device_id):
"""Discover and add a discovered sensor."""
client = hass.data[tellduslive.DOMAIN]
async_add_entities([TelldusLiveSensor(client, device_id)])

async_dispatcher_connect(
hass,
tellduslive.TELLDUS_DISCOVERY_NEW.format(binary_sensor.DOMAIN,
tellduslive.DOMAIN),
async_discover_binary_sensor)


class TelldusLiveSensor(TelldusLiveEntity, BinarySensorDevice):
Expand Down
30 changes: 23 additions & 7 deletions homeassistant/components/cover/tellduslive.py
Expand Up @@ -8,20 +8,36 @@
"""
import logging

from homeassistant.components import tellduslive
from homeassistant.components import cover, tellduslive
from homeassistant.components.cover import CoverDevice
from homeassistant.components.tellduslive.entry import TelldusLiveEntity
from homeassistant.helpers.dispatcher import async_dispatcher_connect

_LOGGER = logging.getLogger(__name__)


def setup_platform(hass, config, add_entities, discovery_info=None):
"""Set up the Telldus Live covers."""
if discovery_info is None:
return

client = hass.data[tellduslive.DOMAIN]
add_entities(TelldusLiveCover(client, cover) for cover in discovery_info)
"""Old way of setting up TelldusLive.

Can only be called when a user accidentally mentions the platform in their
config. But even in that case it would have been ignored.
"""
pass


async def async_setup_entry(hass, config_entry, async_add_entities):
"""Set up tellduslive sensors dynamically."""
async def async_discover_cover(device_id):
"""Discover and add a discovered sensor."""
client = hass.data[tellduslive.DOMAIN]
async_add_entities([TelldusLiveCover(client, device_id)])

async_dispatcher_connect(
hass,
tellduslive.TELLDUS_DISCOVERY_NEW.format(cover.DOMAIN,
tellduslive.DOMAIN),
async_discover_cover,
)


class TelldusLiveCover(TelldusLiveEntity, CoverDevice):
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/discovery.py
Expand Up @@ -49,6 +49,7 @@
SERVICE_DECONZ: 'deconz',
'google_cast': 'cast',
SERVICE_HUE: 'hue',
SERVICE_TELLDUSLIVE: 'tellduslive',
SERVICE_IKEA_TRADFRI: 'tradfri',
'sonos': 'sonos',
}
Expand All @@ -62,7 +63,6 @@
SERVICE_APPLE_TV: ('apple_tv', None),
SERVICE_WINK: ('wink', None),
SERVICE_XIAOMI_GW: ('xiaomi_aqara', None),
SERVICE_TELLDUSLIVE: ('tellduslive', None),
SERVICE_DAIKIN: ('daikin', None),
SERVICE_SABNZBD: ('sabnzbd', None),
SERVICE_SAMSUNG_PRINTER: ('sensor', 'syncthru'),
Expand Down
29 changes: 23 additions & 6 deletions homeassistant/components/light/tellduslive.py
Expand Up @@ -8,20 +8,37 @@
"""
import logging

from homeassistant.components import tellduslive
from homeassistant.components import light, tellduslive
from homeassistant.components.light import (
ATTR_BRIGHTNESS, SUPPORT_BRIGHTNESS, Light)
from homeassistant.components.tellduslive.entry import TelldusLiveEntity
from homeassistant.helpers.dispatcher import async_dispatcher_connect

_LOGGER = logging.getLogger(__name__)


def setup_platform(hass, config, add_entities, discovery_info=None):
"""Set up the Tellstick Net lights."""
if discovery_info is None:
return
client = hass.data[tellduslive.DOMAIN]
add_entities(TelldusLiveLight(client, light) for light in discovery_info)
"""Old way of setting up TelldusLive.

Can only be called when a user accidentally mentions the platform in their
config. But even in that case it would have been ignored.
"""
pass


async def async_setup_entry(hass, config_entry, async_add_entities):
"""Set up tellduslive sensors dynamically."""
async def async_discover_light(device_id):
"""Discover and add a discovered sensor."""
client = hass.data[tellduslive.DOMAIN]
async_add_entities([TelldusLiveLight(client, device_id)])

async_dispatcher_connect(
hass,
tellduslive.TELLDUS_DISCOVERY_NEW.format(light.DOMAIN,
tellduslive.DOMAIN),
async_discover_light,
)


class TelldusLiveLight(TelldusLiveEntity, Light):
Expand Down
28 changes: 21 additions & 7 deletions homeassistant/components/sensor/tellduslive.py
Expand Up @@ -6,11 +6,12 @@
"""
import logging

from homeassistant.components import tellduslive
from homeassistant.components import sensor, tellduslive
from homeassistant.components.tellduslive.entry import TelldusLiveEntity
from homeassistant.const import (
DEVICE_CLASS_HUMIDITY, DEVICE_CLASS_ILLUMINANCE, DEVICE_CLASS_TEMPERATURE,
TEMP_CELSIUS)
from homeassistant.helpers.dispatcher import async_dispatcher_connect

_LOGGER = logging.getLogger(__name__)

Expand Down Expand Up @@ -46,12 +47,25 @@


def setup_platform(hass, config, add_entities, discovery_info=None):
"""Set up the Tellstick sensors."""
if discovery_info is None:
return
client = hass.data[tellduslive.DOMAIN]
add_entities(
TelldusLiveSensor(client, sensor) for sensor in discovery_info)
"""Old way of setting up TelldusLive.

Can only be called when a user accidentally mentions the platform in their
config. But even in that case it would have been ignored.
"""
pass


async def async_setup_entry(hass, config_entry, async_add_entities):
"""Set up tellduslive sensors dynamically."""
async def async_discover_sensor(device_id):
"""Discover and add a discovered sensor."""
client = hass.data[tellduslive.DOMAIN]
async_add_entities([TelldusLiveSensor(client, device_id)])

async_dispatcher_connect(
hass,
tellduslive.TELLDUS_DISCOVERY_NEW.format(
sensor.DOMAIN, tellduslive.DOMAIN), async_discover_sensor)


class TelldusLiveSensor(TelldusLiveEntity):
Expand Down
30 changes: 23 additions & 7 deletions homeassistant/components/switch/tellduslive.py
Expand Up @@ -9,20 +9,36 @@
"""
import logging

from homeassistant.components import tellduslive
from homeassistant.components import switch, tellduslive
from homeassistant.components.tellduslive.entry import TelldusLiveEntity
from homeassistant.helpers.dispatcher import async_dispatcher_connect
from homeassistant.helpers.entity import ToggleEntity

_LOGGER = logging.getLogger(__name__)


def setup_platform(hass, config, add_entities, discovery_info=None):
"""Set up Tellstick switches."""
if discovery_info is None:
return
client = hass.data[tellduslive.DOMAIN]
add_entities(
TelldusLiveSwitch(client, switch) for switch in discovery_info)
"""Old way of setting up TelldusLive.

Can only be called when a user accidentally mentions the platform in their
config. But even in that case it would have been ignored.
"""
pass


async def async_setup_entry(hass, config_entry, async_add_entities):
"""Set up tellduslive sensors dynamically."""
async def async_discover_switch(device_id):
"""Discover and add a discovered sensor."""
client = hass.data[tellduslive.DOMAIN]
async_add_entities([TelldusLiveSwitch(client, device_id)])

async_dispatcher_connect(
hass,
tellduslive.TELLDUS_DISCOVERY_NEW.format(switch.DOMAIN,
tellduslive.DOMAIN),
async_discover_switch,
)


class TelldusLiveSwitch(TelldusLiveEntity, ToggleEntity):
Expand Down
24 changes: 24 additions & 0 deletions homeassistant/components/tellduslive/.translations/en.json
@@ -0,0 +1,24 @@
{
"config": {
"title": "Telldus Live",
"step": {
"user": {
"title": "Pick endpoint.",
"description": "",
"data": {
"host": "Host"
}
},
"auth": {
"title": "Authenticate against TelldusLive",
"description": "To link your TelldusLive account:\n 1. Click the link below\n 2. Login to Telldus Live\n 3. Authorize **{app_name}** (click **Yes**).\n 4. Come back here and click **SUBMIT**.\n\n [Link TelldusLive account]({auth_url})"
}
},
"abort": {
"authorize_url_timeout": "Timeout generating authorize url.",
"authorize_url_fail": "Unknown error generating an authorize url.",
"all_configured": "TelldusLive is already configured",
"unknown": "Unknown error occurred"
}
}
}