Add Tuya cover and scene platform ()

* Add Tuya cover platform

* Add Tuya cover and scene

* fix description

* remove scene default method
pull/15652/head
huangyupeng 2018-07-24 16:29:43 +08:00 committed by Martin Hjelmare
parent d7690c5fda
commit c1f5ead61d
3 changed files with 102 additions and 0 deletions
homeassistant/components

View File

@ -0,0 +1,60 @@
"""
Support for Tuya cover.
For more details about this platform, please refer to the documentation at
https://home-assistant.io/components/cover.tuya/
"""
from homeassistant.components.cover import (
CoverDevice, ENTITY_ID_FORMAT, SUPPORT_OPEN, SUPPORT_CLOSE, SUPPORT_STOP)
from homeassistant.components.tuya import DATA_TUYA, TuyaDevice
DEPENDENCIES = ['tuya']
def setup_platform(hass, config, add_devices, discovery_info=None):
"""Set up Tuya cover devices."""
if discovery_info is None:
return
tuya = hass.data[DATA_TUYA]
dev_ids = discovery_info.get('dev_ids')
devices = []
for dev_id in dev_ids:
device = tuya.get_device_by_id(dev_id)
if device is None:
continue
devices.append(TuyaCover(device))
add_devices(devices)
class TuyaCover(TuyaDevice, CoverDevice):
"""Tuya cover devices."""
def __init__(self, tuya):
"""Init tuya cover device."""
super().__init__(tuya)
self.entity_id = ENTITY_ID_FORMAT.format(tuya.object_id())
@property
def supported_features(self):
"""Flag supported features."""
supported_features = SUPPORT_OPEN | SUPPORT_CLOSE
if self.tuya.support_stop():
supported_features |= SUPPORT_STOP
return supported_features
@property
def is_closed(self):
"""Return if the cover is closed or not."""
return None
def open_cover(self, **kwargs):
"""Open the cover."""
self.tuya.open_cover()
def close_cover(self, **kwargs):
"""Close cover."""
self.tuya.close_cover()
def stop_cover(self, **kwargs):
"""Stop the cover."""
self.tuya.stop_cover()

View File

@ -0,0 +1,40 @@
"""
Support for the Tuya scene.
For more details about this platform, please refer to the documentation at
https://home-assistant.io/components/scene.tuya/
"""
from homeassistant.components.scene import Scene, DOMAIN
from homeassistant.components.tuya import DATA_TUYA, TuyaDevice
DEPENDENCIES = ['tuya']
ENTITY_ID_FORMAT = DOMAIN + '.{}'
def setup_platform(hass, config, add_devices, discovery_info=None):
"""Set up Tuya scenes."""
if discovery_info is None:
return
tuya = hass.data[DATA_TUYA]
dev_ids = discovery_info.get('dev_ids')
devices = []
for dev_id in dev_ids:
device = tuya.get_device_by_id(dev_id)
if device is None:
continue
devices.append(TuyaScene(device))
add_devices(devices)
class TuyaScene(TuyaDevice, Scene):
"""Tuya Scene."""
def __init__(self, tuya):
"""Init Tuya scene."""
super().__init__(tuya)
self.entity_id = ENTITY_ID_FORMAT.format(tuya.object_id())
def activate(self):
"""Activate the scene."""
self.tuya.activate()

View File

@ -34,8 +34,10 @@ SERVICE_PULL_DEVICES = 'pull_devices'
TUYA_TYPE_TO_HA = {
'climate': 'climate',
'cover': 'cover',
'fan': 'fan',
'light': 'light',
'scene': 'scene',
'switch': 'switch',
}