From 9f04c7f626263a3d105846da19e8fb094c785e05 Mon Sep 17 00:00:00 2001 From: vjccruz Date: Fri, 16 Oct 2020 08:16:38 +0100 Subject: [PATCH 1/4] Fixed deprecated entity --- .../custom_components/dohomelight/light.py | 48 +++++++++++-------- 1 file changed, 27 insertions(+), 21 deletions(-) diff --git a/DoHome_HassAssistant_Component/custom_components/dohomelight/light.py b/DoHome_HassAssistant_Component/custom_components/dohomelight/light.py index 5ba9ff7..9c0afea 100644 --- a/DoHome_HassAssistant_Component/custom_components/dohomelight/light.py +++ b/DoHome_HassAssistant_Component/custom_components/dohomelight/light.py @@ -12,7 +12,7 @@ PLATFORM_SCHEMA, SUPPORT_BRIGHTNESS, SUPPORT_COLOR, - Light, + LightEntity, ) try: @@ -22,6 +22,7 @@ _LOGGER = logging.getLogger(__name__) + def setup_platform(hass, config, add_devices, discovery_info=None): light_devices = [] devices = DOHOME_GATEWAY.devices @@ -30,12 +31,12 @@ def setup_platform(hass, config, add_devices, discovery_info=None): _LOGGER.info(device) if(device['type'] == '_DT-WYRGB'): light_devices.append(DoHomeLight(hass, device)) - + if(len(light_devices) > 0): add_devices(light_devices) -class DoHomeLight(DoHomeDevice, Light): +class DoHomeLight(DoHomeDevice, LightEntity): def __init__(self, hass, device): self._device = device @@ -76,27 +77,29 @@ def turn_on(self, **kwargs): self._state = True data = { - "cmd":6, - "r":int(50 * self._rgb[0] / 255)*self._brightness, - "g":int(50 * self._rgb[1] / 255)*self._brightness, - "b":int(50 * self._rgb[2] / 255)*self._brightness, - "w":0, - "m":0} + "cmd": 6, + "r": int(50 * self._rgb[0] / 255)*self._brightness, + "g": int(50 * self._rgb[1] / 255)*self._brightness, + "b": int(50 * self._rgb[2] / 255)*self._brightness, + "w": 0, + "m": 0} op = json.dumps(data) - self._send_cmd(self._device,'cmd=ctrl&devices={[' + self._device["sid"] + ']}&op=' + op + '}', 6) + self._send_cmd( + self._device, 'cmd=ctrl&devices={[' + self._device["sid"] + ']}&op=' + op + '}', 6) def turn_off(self, **kwargs): """Turn the light off.""" self._state = False data = { - "cmd":6, - "r":0, - "g":0, - "b":0, - "w":0, - "m":0} + "cmd": 6, + "r": 0, + "g": 0, + "b": 0, + "w": 0, + "m": 0} op = json.dumps(data) - self._send_cmd(self._device,'cmd=ctrl&devices={[' + self._device["sid"] + ']}&op=' + op + '}', 6) + self._send_cmd( + self._device, 'cmd=ctrl&devices={[' + self._device["sid"] + ']}&op=' + op + '}', 6) def _send_cmd(self, device, cmd, rtn_cmd): @@ -110,14 +113,17 @@ def _send_cmd(self, device, cmd, rtn_cmd): if data is None: return None _LOGGER.debug("result :%s", data.decode("utf-8")) - dic = {i.split("=")[0]:i.split("=")[1] for i in data.decode("utf-8").split("&")} + dic = {i.split("=")[0]: i.split("=")[1] + for i in data.decode("utf-8").split("&")} resp = [] if(dic["dev"][8:12] == device["sid"]): resp = json.loads(dic["op"]) if resp['cmd'] != rtn_cmd: - _LOGGER.debug("Non matching response. Expecting %s, but got %s", rtn_cmd, resp['cmd']) + _LOGGER.debug( + "Non matching response. Expecting %s, but got %s", rtn_cmd, resp['cmd']) return None return resp else: - _LOGGER.debug("Non matching response. device %s, but got %s", device["sid"], dic["dev"][8:12]) - return None \ No newline at end of file + _LOGGER.debug("Non matching response. device %s, but got %s", + device["sid"], dic["dev"][8:12]) + return None From 64a735b00d8c254c395e59f0b238169cb6af26ec Mon Sep 17 00:00:00 2001 From: vjccruz Date: Fri, 16 Oct 2020 08:19:18 +0100 Subject: [PATCH 2/4] Fixed DoHomeDevice.__init__() Added device['name'] to DoHomeDevice.__init__() --- .../custom_components/dohomelight/light.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DoHome_HassAssistant_Component/custom_components/dohomelight/light.py b/DoHome_HassAssistant_Component/custom_components/dohomelight/light.py index 9c0afea..31977d4 100644 --- a/DoHome_HassAssistant_Component/custom_components/dohomelight/light.py +++ b/DoHome_HassAssistant_Component/custom_components/dohomelight/light.py @@ -45,7 +45,7 @@ def __init__(self, hass, device): self._brightness = 100 self._socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) - DoHomeDevice.__init__(self, device) + DoHomeDevice.__init__(self, device['name'], device) @property def brightness(self): From 8a2af9a3469633de935f8d953835e40e80f2f405 Mon Sep 17 00:00:00 2001 From: Vasco Cruz Date: Fri, 16 Oct 2020 08:24:49 +0100 Subject: [PATCH 3/4] Fixed deprecated entity --- .../custom_components/dohomebinarysensor/binary_sensor.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/DoHome_HassAssistant_Component/custom_components/dohomebinarysensor/binary_sensor.py b/DoHome_HassAssistant_Component/custom_components/dohomebinarysensor/binary_sensor.py index a4d73bf..b9b8f2c 100644 --- a/DoHome_HassAssistant_Component/custom_components/dohomebinarysensor/binary_sensor.py +++ b/DoHome_HassAssistant_Component/custom_components/dohomebinarysensor/binary_sensor.py @@ -14,7 +14,7 @@ except ImportError: from custom_components.dohome import (DOHOME_GATEWAY, DoHomeDevice) -from homeassistant.components.binary_sensor import BinarySensorDevice +from homeassistant.components.binary_sensor import BinarySensorEntity NO_CLOSE = 'no_close' @@ -27,6 +27,7 @@ _LOGGER = logging.getLogger(__name__) + def setup_platform(hass, config, add_devices, discovery_info=None): """Perform the setup for Xiaomi devices.""" sensor_devices = [] @@ -36,12 +37,12 @@ def setup_platform(hass, config, add_devices, discovery_info=None): _LOGGER.info(device) if(device['type'] == '_MOTION' or device['type'] == '_THIMR'): sensor_devices.append(MotionSensor(hass, device)) - + if(len(sensor_devices) > 0): add_devices(sensor_devices) -class MotionSensor(DoHomeDevice, BinarySensorDevice): +class MotionSensor(DoHomeDevice, BinarySensorEntity): def __init__(self, hass, device): self._device = device From c38be855af7f24e1dbf291bcc213b77abe1a5df3 Mon Sep 17 00:00:00 2001 From: Vasco Cruz Date: Fri, 16 Oct 2020 08:25:32 +0100 Subject: [PATCH 4/4] Fixed deprecated entity --- .../custom_components/dohomeswitch/switch.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/DoHome_HassAssistant_Component/custom_components/dohomeswitch/switch.py b/DoHome_HassAssistant_Component/custom_components/dohomeswitch/switch.py index 244dba1..2117368 100644 --- a/DoHome_HassAssistant_Component/custom_components/dohomeswitch/switch.py +++ b/DoHome_HassAssistant_Component/custom_components/dohomeswitch/switch.py @@ -4,7 +4,7 @@ from datetime import timedelta from homeassistant.helpers.event import track_time_interval -from homeassistant.components.switch import SwitchDevice +from homeassistant.components.switch import SwitchEntity try: from homeassistant.components.dohome import (DOHOME_GATEWAY, DoHomeDevice) except ImportError: @@ -35,7 +35,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None): add_devices(switch_devices) -class DoHomeSwitch(DoHomeDevice, SwitchDevice): +class DoHomeSwitch(DoHomeDevice, SwitchEntity): def __init__(self, hass, name, data_key, device): self._device = device