From 380d184c9ce41ee5b9b08cdff1e04aacf54d17b5 Mon Sep 17 00:00:00 2001 From: Scott Phillips Date: Thu, 21 Mar 2024 19:37:38 +1100 Subject: [PATCH] Address linting --- custom_components/echonetlite/__init__.py | 6 +-- custom_components/echonetlite/cover.py | 64 ++++++++++++++++------- custom_components/echonetlite/number.py | 2 +- 3 files changed, 50 insertions(+), 22 deletions(-) diff --git a/custom_components/echonetlite/__init__.py b/custom_components/echonetlite/__init__.py index 62ba71c..b17cfcc 100644 --- a/custom_components/echonetlite/__init__.py +++ b/custom_components/echonetlite/__init__.py @@ -75,15 +75,15 @@ MAX_UPDATE_BATCH_SIZE = 10 MIN_UPDATE_BATCH_SIZE = 3 -def get_device_name( - connector, config -) -> str: + +def get_device_name(connector, config) -> str: if connector._name: return connector._name if connector._instance._eojci > 1: return f"{config.title} {connector._instance._eojci}" return config.title + def get_name_by_epc_code( jgc: int, jcc: int, code: int, unknown: str | None = None ) -> str: diff --git a/custom_components/echonetlite/cover.py b/custom_components/echonetlite/cover.py index b7bce27..32b322e 100644 --- a/custom_components/echonetlite/cover.py +++ b/custom_components/echonetlite/cover.py @@ -27,11 +27,20 @@ TILT_RANGE = (1, 180) _LOGGER = logging.getLogger(__name__) + async def async_setup_entry(hass, config_entry, async_add_devices): """Set up entry.""" entities = [] for entity in hass.data[DOMAIN][config_entry.entry_id]: - if entity['instance']['eojgc'] == 0x02 and entity['instance']['eojcc'] in (0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66): + if entity["instance"]["eojgc"] == 0x02 and entity["instance"]["eojcc"] in ( + 0x60, + 0x61, + 0x62, + 0x63, + 0x64, + 0x65, + 0x66, + ): # 0x60: "Electrically operated blind/shade" # 0x61: "Electrically operated shutter" # 0x62: "Electrically operated curtain" @@ -39,7 +48,7 @@ async def async_setup_entry(hass, config_entry, async_add_devices): # 0x64: "Electrically operated gate" # 0x65: "Electrically operated window" # 0x66: "Automatically operated entrance door/sliding door" - entities.append(EchonetCover(entity['echonetlite'], config_entry)) + entities.append(EchonetCover(entity["echonetlite"], config_entry)) async_add_devices(entities, True) @@ -52,7 +61,9 @@ def __init__(self, connector, config): self._name = name self._device_name = name self._connector = connector # new line - self._uid = self._connector._uidi if self._connector._uidi else self._connector._uid + self._uid = ( + self._connector._uidi if self._connector._uidi else self._connector._uid + ) self._attr_is_closed = False self._server_state = self._connector._api._state[ self._connector._instance._host @@ -71,7 +82,7 @@ def __init__(self, connector, config): CoverEntityFeature.OPEN_TILT | CoverEntityFeature.CLOSE_TILT # not supported individually (just global STOP) - #| CoverEntityFeature.STOP_TILT + # | CoverEntityFeature.STOP_TILT | CoverEntityFeature.SET_TILT_POSITION ) @@ -115,7 +126,9 @@ async def async_open_cover_tilt(self, **kwargs: Any) -> None: self._connector._update_data[ENL_BLIND_ANGLE] = hex(180) async def async_set_cover_tilt_position(self, **kwargs: Any) -> None: - tilt = math.ceil(percentage_to_ranged_value(TILT_RANGE, kwargs[ATTR_TILT_POSITION])) + tilt = math.ceil( + percentage_to_ranged_value(TILT_RANGE, kwargs[ATTR_TILT_POSITION]) + ) await self._connector._instance.setMessage(ENL_BLIND_ANGLE, tilt) self._connector._update_data[ENL_BLIND_ANGLE] = hex(tilt) @@ -131,16 +144,28 @@ async def async_update(self): await self._connector.async_update() def update_attr(self): - self._attr_current_cover_position = int(self._connector._update_data[ENL_OPENING_LEVEL], 16) + self._attr_current_cover_position = int( + self._connector._update_data[ENL_OPENING_LEVEL], 16 + ) self._attr_is_closed = self._attr_current_cover_position == 0 if ENL_OPENCLOSE_STATUS in self._connector._update_data: - self._attr_is_opening = int(self._connector._update_data[ENL_OPENCLOSE_STATUS], 16) == 0x43 - self._attr_is_closing = int(self._connector._update_data[ENL_OPENCLOSE_STATUS], 16) == 0x44 + self._attr_is_opening = ( + int(self._connector._update_data[ENL_OPENCLOSE_STATUS], 16) == 0x43 + ) + self._attr_is_closing = ( + int(self._connector._update_data[ENL_OPENCLOSE_STATUS], 16) == 0x44 + ) else: - self._attr_is_opening = self._connector._update_data[ENL_OPENSTATE] == "open" - self._attr_is_closing = self._connector._update_data[ENL_OPENSTATE] == "close" + self._attr_is_opening = ( + self._connector._update_data[ENL_OPENSTATE] == "open" + ) + self._attr_is_closing = ( + self._connector._update_data[ENL_OPENSTATE] == "close" + ) if ENL_BLIND_ANGLE in self._connector._update_data: - self._attr_current_cover_tilt_position = ranged_value_to_percentage(TILT_RANGE, int(self._connector._update_data[ENL_BLIND_ANGLE], 16)) + self._attr_current_cover_tilt_position = ranged_value_to_percentage( + TILT_RANGE, int(self._connector._update_data[ENL_BLIND_ANGLE], 16) + ) @property def supported_features(self): @@ -155,12 +180,15 @@ def unique_id(self): @property def device_info(self): return { - "identifiers": {( - DOMAIN, self._connector._uid, - self._connector._instance._eojgc, - self._connector._instance._eojcc, - self._connector._instance._eojci - )}, + "identifiers": { + ( + DOMAIN, + self._connector._uid, + self._connector._instance._eojgc, + self._connector._instance._eojcc, + self._connector._instance._eojci, + ) + }, "name": self._device_name, "manufacturer": self._connector._manufacturer + ( @@ -189,7 +217,7 @@ async def async_added_to_hass(self): self._connector.add_update_option_listener(self.update_option_listener) self._connector.register_async_update_callbacks(self.async_update_callback) - async def async_update_callback(self, isPush = False): + async def async_update_callback(self, isPush=False): changed = ( self._olddata != self._connector._update_data ) or self._attr_available != self._server_state["available"] diff --git a/custom_components/echonetlite/number.py b/custom_components/echonetlite/number.py index de51a60..2d3cfe8 100644 --- a/custom_components/echonetlite/number.py +++ b/custom_components/echonetlite/number.py @@ -38,7 +38,7 @@ async def async_setup_entry(hass, config, async_add_entities, discovery_info=Non entity["echonetlite"], config, op_code, - _enl_op_codes[op_code] + _enl_op_codes[op_code], ) )