From c93b6d8c552c8f9c0b7e39dd20d056d8d82ea0e8 Mon Sep 17 00:00:00 2001 From: roleo Date: Sun, 6 Mar 2022 16:01:41 +0100 Subject: [PATCH] Code cleaning --- custom_components/yi_hack/binary_sensor.py | 2 - custom_components/yi_hack/common.py | 11 +++-- custom_components/yi_hack/media_player.py | 51 ++++++++++++++++------ custom_components/yi_hack/switch.py | 4 -- 4 files changed, 45 insertions(+), 23 deletions(-) diff --git a/custom_components/yi_hack/binary_sensor.py b/custom_components/yi_hack/binary_sensor.py index d3b02dc..ab810c5 100644 --- a/custom_components/yi_hack/binary_sensor.py +++ b/custom_components/yi_hack/binary_sensor.py @@ -22,8 +22,6 @@ CONF_TOPIC_STATUS, CONF_WILL_MSG, DEFAULT_BRAND, DOMAIN, MSTAR, SONOFF, V5) -ICON = "mdi:update" - _LOGGER = logging.getLogger(__name__) diff --git a/custom_components/yi_hack/common.py b/custom_components/yi_hack/common.py index c1ebfdb..9d52f8e 100644 --- a/custom_components/yi_hack/common.py +++ b/custom_components/yi_hack/common.py @@ -6,7 +6,13 @@ import requests from requests.auth import HTTPBasicAuth -from homeassistant.const import CONF_HOST, CONF_PASSWORD, CONF_PORT, CONF_USERNAME +from homeassistant.const import ( + CONF_HOST, + CONF_NAME, + CONF_PASSWORD, + CONF_PORT, + CONF_USERNAME, +) from homeassistant.util import dt as dt_util from .const import ( @@ -19,9 +25,6 @@ _LOGGER = logging.getLogger(__name__) -#device_is_on = None -#end_of_power_off = None -#end_of_power_on = None def get_status(config): """Get system status from camera.""" diff --git a/custom_components/yi_hack/media_player.py b/custom_components/yi_hack/media_player.py index d02687b..a0356b7 100644 --- a/custom_components/yi_hack/media_player.py +++ b/custom_components/yi_hack/media_player.py @@ -7,21 +7,46 @@ import requests from requests.auth import HTTPBasicAuth -from homeassistant.components.media_player import (DEVICE_CLASS_SPEAKER, - MediaPlayerEntity) -from homeassistant.components.media_player.const import (MEDIA_TYPE_MUSIC, - SUPPORT_PLAY_MEDIA, - SUPPORT_TURN_OFF, - SUPPORT_TURN_ON) -from homeassistant.const import (CONF_HOST, CONF_MAC, CONF_NAME, CONF_PASSWORD, - CONF_PORT, CONF_USERNAME, STATE_IDLE, - STATE_OFF, STATE_ON, STATE_PLAYING) +from homeassistant.components.media_player import ( + DEVICE_CLASS_SPEAKER, + MediaPlayerEntity +) +from homeassistant.components.media_player.const import ( + MEDIA_TYPE_MUSIC, + SUPPORT_PLAY_MEDIA, + SUPPORT_TURN_OFF, + SUPPORT_TURN_ON +) +from homeassistant.const import ( + CONF_HOST, + CONF_MAC, + CONF_NAME, + CONF_PASSWORD, + CONF_PORT, + CONF_USERNAME, + STATE_IDLE, + STATE_OFF, + STATE_ON, + STATE_PLAYING +) from homeassistant.helpers.device_registry import CONNECTION_NETWORK_MAC -from .common import (get_privacy, set_power_off_in_progress, - set_power_on_in_progress, set_privacy) -from .const import (ALLWINNER, ALLWINNERV2, CONF_BOOST_SPEAKER, CONF_HACK_NAME, - DEFAULT_BRAND, DOMAIN, HTTP_TIMEOUT, MSTAR) +from .common import ( + get_privacy, + set_power_off_in_progress, + set_power_on_in_progress, + set_privacy +) +from .const import ( + ALLWINNER, + ALLWINNERV2, + CONF_BOOST_SPEAKER, + CONF_HACK_NAME, + DEFAULT_BRAND, + DOMAIN, + HTTP_TIMEOUT, + MSTAR +) SUPPORT_YIHACK_MEDIA = ( SUPPORT_PLAY_MEDIA diff --git a/custom_components/yi_hack/switch.py b/custom_components/yi_hack/switch.py index 391d539..571e52b 100644 --- a/custom_components/yi_hack/switch.py +++ b/custom_components/yi_hack/switch.py @@ -41,8 +41,6 @@ def update(self): (CONF_USERNAME, self._user), (CONF_PASSWORD, self._password), ]) - #self._state = self.hass.async_add_executor_job(get_privacy, self.hass, conf) - #self.hass.async_add_executor_job(set_privacy, self.hass, self._state) self._state = get_privacy(self.hass, self._device_name, conf) set_privacy(self.hass, self._device_name, self._state) @@ -54,7 +52,6 @@ def turn_off(self): (CONF_USERNAME, self._user), (CONF_PASSWORD, self._password), ]) - #privacy = self.hass.async_add_executor_job(get_privacy, self.hass) if get_privacy(self.hass, self._device_name): _LOGGER.debug("Turn off privacy, camera %s", self._name) set_power_off_in_progress(self.hass, self._device_name) @@ -70,7 +67,6 @@ def turn_on(self): (CONF_USERNAME, self._user), (CONF_PASSWORD, self._password), ]) - #privacy = self.hass.async_add_executor_job(get_privacy, self.hass) if not get_privacy(self.hass, self._device_name): _LOGGER.debug("Turn on privacy, camera %s", self._name) set_power_on_in_progress(self.hass, self._device_name)