From db03bd3a8ddd96b427f8a260776eed8d9d8a12a8 Mon Sep 17 00:00:00 2001 From: rospogrigio Date: Thu, 21 May 2020 07:55:35 +0200 Subject: [PATCH] Updated for HA 110.0 (CoverEntity and SwitchEntity instead of CoverDevice and SwitchDevice) --- custom_components/localtuya/cover.py | 10 +++++----- custom_components/localtuya/pytuya/__init__.py | 4 ++-- custom_components/localtuya/switch.py | 4 ++-- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/custom_components/localtuya/cover.py b/custom_components/localtuya/cover.py index 785c1f7..0a4a3b1 100644 --- a/custom_components/localtuya/cover.py +++ b/custom_components/localtuya/cover.py @@ -20,7 +20,7 @@ import requests import voluptuous as vol from homeassistant.components.cover import ( - CoverDevice, + CoverEntity, PLATFORM_SCHEMA, SUPPORT_CLOSE, SUPPORT_OPEN, @@ -28,7 +28,7 @@ from homeassistant.components.cover import ( ) """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) import homeassistant.helpers.config_validation as cv from time import time, sleep @@ -66,7 +66,7 @@ def setup_platform(hass, config, add_entities, discovery_info=None): from . import pytuya 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))) cover_device = TuyaCoverCache(localtuyadevice) @@ -86,7 +86,7 @@ def setup_platform(hass, config, add_entities, discovery_info=None): class TuyaCoverCache: - """Cache wrapper for pytuya.CoverDevice""" + """Cache wrapper for pytuya.CoverEntity""" def __init__(self, device): """Initialize the cache.""" @@ -135,7 +135,7 @@ class TuyaCoverCache: finally: self._lock.release() -class TuyaDevice(CoverDevice): +class TuyaDevice(CoverEntity): """Tuya cover devices.""" def __init__(self, device, name, friendly_name, icon, switchid): diff --git a/custom_components/localtuya/pytuya/__init__.py b/custom_components/localtuya/pytuya/__init__.py index cec00f6..8e2a01c 100644 --- a/custom_components/localtuya/pytuya/__init__.py +++ b/custom_components/localtuya/pytuya/__init__.py @@ -436,7 +436,7 @@ class OutletDevice(Device): super(OutletDevice, self).__init__(dev_id, address, local_key, dev_type) -class CoverDevice(Device): +class CoverEntity(Device): DPS_INDEX_MOVE = '1' DPS_INDEX_BL = '101' @@ -455,7 +455,7 @@ class CoverDevice(Device): else: print('Using PyCrypto ', Crypto.version_info) 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): """Turn the device on""" diff --git a/custom_components/localtuya/switch.py b/custom_components/localtuya/switch.py index 60ac1b7..67a8931 100644 --- a/custom_components/localtuya/switch.py +++ b/custom_components/localtuya/switch.py @@ -27,7 +27,7 @@ switch: import logging 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) import homeassistant.helpers.config_validation as cv from time import time, sleep @@ -173,7 +173,7 @@ class TuyaCache: finally: self._lock.release() -class TuyaDevice(SwitchDevice): +class TuyaDevice(SwitchEntity): """Representation of a Tuya switch.""" def __init__(self, device, name, friendly_name, icon, switchid, attr_current, attr_consumption, attr_voltage):