Updated for HA 110.0 (CoverEntity and SwitchEntity instead of CoverDevice and SwitchDevice)
This commit is contained in:
@@ -20,7 +20,7 @@ import requests
|
|||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
from homeassistant.components.cover import (
|
from homeassistant.components.cover import (
|
||||||
CoverDevice,
|
CoverEntity,
|
||||||
PLATFORM_SCHEMA,
|
PLATFORM_SCHEMA,
|
||||||
SUPPORT_CLOSE,
|
SUPPORT_CLOSE,
|
||||||
SUPPORT_OPEN,
|
SUPPORT_OPEN,
|
||||||
@@ -28,7 +28,7 @@ from homeassistant.components.cover import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
"""from . import DATA_TUYA, TuyaDevice"""
|
"""from . import DATA_TUYA, TuyaDevice"""
|
||||||
from homeassistant.components.cover import ENTITY_ID_FORMAT, CoverDevice, PLATFORM_SCHEMA
|
from homeassistant.components.cover import ENTITY_ID_FORMAT, CoverEntity, PLATFORM_SCHEMA
|
||||||
from homeassistant.const import (CONF_HOST, CONF_ID, CONF_FRIENDLY_NAME, CONF_ICON, CONF_NAME)
|
from homeassistant.const import (CONF_HOST, CONF_ID, CONF_FRIENDLY_NAME, CONF_ICON, CONF_NAME)
|
||||||
import homeassistant.helpers.config_validation as cv
|
import homeassistant.helpers.config_validation as cv
|
||||||
from time import time, sleep
|
from time import time, sleep
|
||||||
@@ -66,7 +66,7 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
|
|||||||
from . import pytuya
|
from . import pytuya
|
||||||
|
|
||||||
covers = []
|
covers = []
|
||||||
localtuyadevice = pytuya.CoverDevice(config.get(CONF_DEVICE_ID), config.get(CONF_HOST), config.get(CONF_LOCAL_KEY))
|
localtuyadevice = pytuya.CoverEntity(config.get(CONF_DEVICE_ID), config.get(CONF_HOST), config.get(CONF_LOCAL_KEY))
|
||||||
localtuyadevice.set_version(float(config.get(CONF_PROTOCOL_VERSION)))
|
localtuyadevice.set_version(float(config.get(CONF_PROTOCOL_VERSION)))
|
||||||
|
|
||||||
cover_device = TuyaCoverCache(localtuyadevice)
|
cover_device = TuyaCoverCache(localtuyadevice)
|
||||||
@@ -86,7 +86,7 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
|
|||||||
|
|
||||||
|
|
||||||
class TuyaCoverCache:
|
class TuyaCoverCache:
|
||||||
"""Cache wrapper for pytuya.CoverDevice"""
|
"""Cache wrapper for pytuya.CoverEntity"""
|
||||||
|
|
||||||
def __init__(self, device):
|
def __init__(self, device):
|
||||||
"""Initialize the cache."""
|
"""Initialize the cache."""
|
||||||
@@ -135,7 +135,7 @@ class TuyaCoverCache:
|
|||||||
finally:
|
finally:
|
||||||
self._lock.release()
|
self._lock.release()
|
||||||
|
|
||||||
class TuyaDevice(CoverDevice):
|
class TuyaDevice(CoverEntity):
|
||||||
"""Tuya cover devices."""
|
"""Tuya cover devices."""
|
||||||
|
|
||||||
def __init__(self, device, name, friendly_name, icon, switchid):
|
def __init__(self, device, name, friendly_name, icon, switchid):
|
||||||
|
@@ -436,7 +436,7 @@ class OutletDevice(Device):
|
|||||||
super(OutletDevice, self).__init__(dev_id, address, local_key, dev_type)
|
super(OutletDevice, self).__init__(dev_id, address, local_key, dev_type)
|
||||||
|
|
||||||
|
|
||||||
class CoverDevice(Device):
|
class CoverEntity(Device):
|
||||||
DPS_INDEX_MOVE = '1'
|
DPS_INDEX_MOVE = '1'
|
||||||
DPS_INDEX_BL = '101'
|
DPS_INDEX_BL = '101'
|
||||||
|
|
||||||
@@ -455,7 +455,7 @@ class CoverDevice(Device):
|
|||||||
else:
|
else:
|
||||||
print('Using PyCrypto ', Crypto.version_info)
|
print('Using PyCrypto ', Crypto.version_info)
|
||||||
print('Using PyCrypto from ', Crypto.__file__)
|
print('Using PyCrypto from ', Crypto.__file__)
|
||||||
super(CoverDevice, self).__init__(dev_id, address, local_key, dev_type)
|
super(CoverEntity, self).__init__(dev_id, address, local_key, dev_type)
|
||||||
|
|
||||||
def open_cover(self, switch=1):
|
def open_cover(self, switch=1):
|
||||||
"""Turn the device on"""
|
"""Turn the device on"""
|
||||||
|
@@ -27,7 +27,7 @@ switch:
|
|||||||
import logging
|
import logging
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
from homeassistant.components.switch import ENTITY_ID_FORMAT, SwitchDevice, PLATFORM_SCHEMA
|
from homeassistant.components.switch import ENTITY_ID_FORMAT, SwitchEntity, PLATFORM_SCHEMA
|
||||||
from homeassistant.const import (CONF_HOST, CONF_ID, CONF_SWITCHES, CONF_FRIENDLY_NAME, CONF_ICON, CONF_NAME)
|
from homeassistant.const import (CONF_HOST, CONF_ID, CONF_SWITCHES, CONF_FRIENDLY_NAME, CONF_ICON, CONF_NAME)
|
||||||
import homeassistant.helpers.config_validation as cv
|
import homeassistant.helpers.config_validation as cv
|
||||||
from time import time, sleep
|
from time import time, sleep
|
||||||
@@ -173,7 +173,7 @@ class TuyaCache:
|
|||||||
finally:
|
finally:
|
||||||
self._lock.release()
|
self._lock.release()
|
||||||
|
|
||||||
class TuyaDevice(SwitchDevice):
|
class TuyaDevice(SwitchEntity):
|
||||||
"""Representation of a Tuya switch."""
|
"""Representation of a Tuya switch."""
|
||||||
|
|
||||||
def __init__(self, device, name, friendly_name, icon, switchid, attr_current, attr_consumption, attr_voltage):
|
def __init__(self, device, name, friendly_name, icon, switchid, attr_current, attr_consumption, attr_voltage):
|
||||||
|
Reference in New Issue
Block a user