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 diff --git a/DoHome_HassAssistant_Component/custom_components/dohomelight/light.py b/DoHome_HassAssistant_Component/custom_components/dohomelight/light.py index 5ba9ff7..31977d4 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 @@ -44,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): @@ -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 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