From 6b3a1c482fef8609bac86bb80cf1133435054802 Mon Sep 17 00:00:00 2001 From: Necroneco Date: Thu, 5 Sep 2024 14:58:37 +0800 Subject: [PATCH] ruff check fix --- custom_components/ds_air/__init__.py | 4 +- custom_components/ds_air/climate.py | 33 ++++++------- custom_components/ds_air/config_flow.py | 1 + custom_components/ds_air/const.py | 1 - custom_components/ds_air/descriptions.py | 3 +- .../ds_air/ds_air_service/__init__.py | 2 +- .../ds_air/ds_air_service/dao.py | 9 ++-- .../ds_air/ds_air_service/decoder.py | 49 +++++++++---------- .../ds_air/ds_air_service/param.py | 12 ++--- .../ds_air/ds_air_service/service.py | 10 ++-- custom_components/ds_air/sensor.py | 4 +- 11 files changed, 59 insertions(+), 69 deletions(-) diff --git a/custom_components/ds_air/__init__.py b/custom_components/ds_air/__init__.py index b335381..68ebe74 100644 --- a/custom_components/ds_air/__init__.py +++ b/custom_components/ds_air/__init__.py @@ -1,5 +1,4 @@ -""" -Platform for DS-AIR of Daikin +"""Platform for DS-AIR of Daikin https://www.daikin-china.com.cn/newha/products/4/19/DS-AIR/ """ @@ -13,7 +12,6 @@ from .const import CONF_GW, DEFAULT_GW, DEFAULT_HOST, DEFAULT_PORT, DOMAIN from .ds_air_service import Config, Service - _LOGGER = logging.getLogger(__name__) PLATFORMS = [ diff --git a/custom_components/ds_air/climate.py b/custom_components/ds_air/climate.py index 0a8172d..72a4098 100644 --- a/custom_components/ds_air/climate.py +++ b/custom_components/ds_air/climate.py @@ -1,5 +1,4 @@ -""" -Daikin platform that offers climate devices. +"""Daikin platform that offers climate devices. For more details about this platform, please refer to the documentation https://home-assistant.io/components/demo/ @@ -8,15 +7,16 @@ import logging import voluptuous as vol + from homeassistant.components.climate import ( - ClimateEntity, - ClimateEntityFeature, - HVACAction, - HVACMode, PLATFORM_SCHEMA, PRESET_COMFORT, PRESET_NONE, PRESET_SLEEP, + ClimateEntity, + ClimateEntityFeature, + HVACAction, + HVACMode, ) from homeassistant.config_entries import ConfigEntry from homeassistant.const import ( @@ -46,8 +46,7 @@ get_fan_direction_name, get_mode_name, ) -from .ds_air_service import AirCon, AirConStatus, EnumControl, display, Service - +from .ds_air_service import AirCon, AirConStatus, EnumControl, Service, display _SUPPORT_FLAGS = ( ClimateEntityFeature.TARGET_TEMPERATURE @@ -230,7 +229,7 @@ def hvac_mode(self) -> HVACMode | None: @property def hvac_modes(self) -> list[HVACMode]: """Return the list of available hvac operation modes.""" - li = [] + li: list[HVACMode] = [] aircon = self._device_info if aircon.cool_mode: li.append(HVACMode.COOL) @@ -250,11 +249,10 @@ def current_temperature(self) -> float | None: """Return the current temperature.""" if self._link_cur_temp: return self._attr_current_temperature + elif self._device_info.config.is_c611: + return None else: - if self._device_info.config.is_c611: - return None - else: - return self._device_info.status.current_temp / 10 + return self._device_info.status.current_temp / 10 @property def target_temperature(self) -> float | None: @@ -412,11 +410,10 @@ def set_preset_mode(self, preset_mode: str) -> None: mode = m.RELAX else: mode = m.COLD - else: - if preset_mode == PRESET_SLEEP: - mode = m.SLEEP - elif preset_mode == PRESET_COMFORT: - mode = m.RELAX + elif preset_mode == PRESET_SLEEP: + mode = m.SLEEP + elif preset_mode == PRESET_COMFORT: + mode = m.RELAX status.mode = mode new_status.mode = mode self.service.control(self._device_info, new_status) diff --git a/custom_components/ds_air/config_flow.py b/custom_components/ds_air/config_flow.py index da27f8d..f49a2a3 100644 --- a/custom_components/ds_air/config_flow.py +++ b/custom_components/ds_air/config_flow.py @@ -4,6 +4,7 @@ from typing import Any import voluptuous as vol + from homeassistant.components.sensor import SensorDeviceClass from homeassistant.config_entries import ( ConfigEntry, diff --git a/custom_components/ds_air/const.py b/custom_components/ds_air/const.py index ef6519f..63eb105 100644 --- a/custom_components/ds_air/const.py +++ b/custom_components/ds_air/const.py @@ -9,7 +9,6 @@ from .ds_air_service import EnumControl - DOMAIN = "ds_air" CONF_GW = "gw" DEFAULT_HOST = "192.168.1." diff --git a/custom_components/ds_air/descriptions.py b/custom_components/ds_air/descriptions.py index 8e78678..758c44a 100644 --- a/custom_components/ds_air/descriptions.py +++ b/custom_components/ds_air/descriptions.py @@ -1,5 +1,6 @@ +from collections.abc import Callable from dataclasses import dataclass -from typing import Any, Callable +from typing import Any from homeassistant.components.sensor import ( SensorDeviceClass, diff --git a/custom_components/ds_air/ds_air_service/__init__.py b/custom_components/ds_air/ds_air_service/__init__.py index 391a982..18f7365 100644 --- a/custom_components/ds_air/ds_air_service/__init__.py +++ b/custom_components/ds_air/ds_air_service/__init__.py @@ -1,5 +1,5 @@ from .config import Config from .ctrl_enum import EnumControl -from .dao import AirCon, AirConStatus, Sensor, UNINITIALIZED_VALUE +from .dao import UNINITIALIZED_VALUE, AirCon, AirConStatus, Sensor from .display import display from .service import Service diff --git a/custom_components/ds_air/ds_air_service/dao.py b/custom_components/ds_air/ds_air_service/dao.py index 26ef804..26f90f4 100644 --- a/custom_components/ds_air/ds_air_service/dao.py +++ b/custom_components/ds_air/ds_air_service/dao.py @@ -1,6 +1,6 @@ import time -from typing import Optional +from .config import Config from .ctrl_enum import ( EnumControl, EnumDevice, @@ -9,7 +9,6 @@ EnumOutDoorRunCond, EnumSwitch, ) -from .config import Config class Device: @@ -175,12 +174,12 @@ class Room: def __init__(self): self.air_con = None self.alias: str = "" - self.geothermic: Optional[Geothermic] = None - self.hd: Optional[HD] = None + self.geothermic: Geothermic | None = None + self.hd: HD | None = None self.hd_room: bool = False self.sensor_room: bool = False self.icon: str = "" self.id: int = 0 self.name: str = "" self.type: int = 0 - self.ventilation: Optional[Ventilation] = Ventilation() + self.ventilation: Ventilation | None = Ventilation() diff --git a/custom_components/ds_air/ds_air_service/decoder.py b/custom_components/ds_air/ds_air_service/decoder.py index 2436ba3..6b0b80b 100644 --- a/custom_components/ds_air/ds_air_service/decoder.py +++ b/custom_components/ds_air/ds_air_service/decoder.py @@ -17,14 +17,14 @@ ThreeDFresh, ) from .dao import ( + HD, + UNINITIALIZED_VALUE, AirCon, AirConStatus, Device, Geothermic, - HD, Room, Sensor, - UNINITIALIZED_VALUE, Ventilation, get_device_by_aircon, ) @@ -190,10 +190,10 @@ def __init__(self, cmd_id: int, targe: EnumDevice, cmd_type: EnumCmdType): BaseBean.__init__(self, cmd_id, targe, cmd_type) def load_bytes(self, b: bytes, config: Config) -> None: - """do nothing""" + """Do nothing""" def do(self, service: Service) -> None: - """do nothing""" + """Do nothing""" class HeartbeatResult(BaseResult): @@ -490,33 +490,33 @@ def load_bytes(self, b: bytes, config: Config) -> None: device_count = d.read2() for unit_id in range(device_count): if ( - EnumDevice.AIRCON == device - or EnumDevice.NEWAIRCON == device - or EnumDevice.BATHROOM == device + device == EnumDevice.AIRCON + or device == EnumDevice.NEWAIRCON + or device == EnumDevice.BATHROOM ): dev = AirCon(config) room.air_con = dev - dev.new_air_con = EnumDevice.NEWAIRCON == device - dev.bath_room = EnumDevice.BATHROOM == device - elif EnumDevice.GEOTHERMIC == device: + dev.new_air_con = device == EnumDevice.NEWAIRCON + dev.bath_room = device == EnumDevice.BATHROOM + elif device == EnumDevice.GEOTHERMIC: dev = Geothermic() room.geothermic = dev - elif EnumDevice.HD == device: + elif device == EnumDevice.HD: dev = HD() self.hds.append(dev) room.hd_room = True room.hd = dev - elif EnumDevice.SENSOR == device: + elif device == EnumDevice.SENSOR: dev = Sensor() self.sensors.append(dev) room.sensor_room = True elif ( - EnumDevice.VENTILATION == device - or EnumDevice.SMALL_VAM == device + device == EnumDevice.VENTILATION + or device == EnumDevice.SMALL_VAM ): dev = Ventilation() room.ventilation = dev - dev.is_small_vam = EnumDevice.SMALL_VAM == device + dev.is_small_vam = device == EnumDevice.SMALL_VAM else: dev = Device() dev.room_id = room.id @@ -585,7 +585,7 @@ def __init__(self, cmd_id: int, target: EnumDevice): ) def load_bytes(self, b: bytes, config: Config) -> None: - """todo""" + """Todo""" class QueryScheduleIDResult(BaseResult): @@ -593,7 +593,7 @@ def __init__(self, cmd_id: int, target: EnumDevice): BaseResult.__init__(self, cmd_id, target, EnumCmdType.SYS_QUERY_SCHEDULE_ID) def load_bytes(self, b: bytes, config: Config) -> None: - """todo""" + """Todo""" class HandShakeResult(BaseResult): @@ -619,10 +619,10 @@ def __init__(self, cmd_id: int, target: EnumDevice): self._time: str = "" def load_bytes(self, b: bytes, config: Config) -> None: - """todo""" + """Todo""" def do(self, service: Service) -> None: - """todo""" + """Todo""" class CmdTransferResult(BaseResult): @@ -630,7 +630,7 @@ def __init__(self, cmd_id: int, target: EnumDevice): BaseResult.__init__(self, cmd_id, target, EnumCmdType.SYS_CMD_TRANSFER) def load_bytes(self, b: bytes, config: Config) -> None: - """todo""" + """Todo""" class QueryScheduleFinish(BaseResult): @@ -638,7 +638,7 @@ def __init__(self, cmd_id: int, target: EnumDevice): BaseResult.__init__(self, cmd_id, target, EnumCmdType.SYS_QUERY_SCHEDULE_FINISH) def load_bytes(self, b: bytes, config: Config) -> None: - """todo""" + """Todo""" class AirConStatusChangedResult(BaseResult): @@ -739,9 +739,8 @@ def load_bytes(self, b: bytes, config: Config) -> None: if self.target == EnumDevice.NEWAIRCON: if flag >> 6 & 1: self.humidity = EnumControl.Humidity(d.read1()) - else: - if flag >> 7 & 1: - self.breathe = EnumControl.Breathe(d.read1()) + elif flag >> 7 & 1: + self.breathe = EnumControl.Breathe(d.read1()) def do(self, service: Service) -> None: status = AirConStatus( @@ -858,7 +857,7 @@ def __init__(self, cmd_id: int, target: EnumDevice): BaseResult.__init__(self, cmd_id, target, EnumCmdType.QUERY_SCENARIO_SETTING) def load_bytes(self, b: bytes, config: Config) -> None: - """todo""" + """Todo""" class UnknownResult(BaseResult): diff --git a/custom_components/ds_air/ds_air_service/param.py b/custom_components/ds_air/ds_air_service/param.py index 9eb22bc..edb21ec 100644 --- a/custom_components/ds_air/ds_air_service/param.py +++ b/custom_components/ds_air/ds_air_service/param.py @@ -1,6 +1,4 @@ import struct -import typing -from typing import Optional from .base_bean import BaseBean from .config import Config @@ -114,7 +112,7 @@ def __init__(self): class GetRoomInfoParam(SystemParam): def __init__(self): SystemParam.__init__(self, EnumCmdType.SYS_GET_ROOM_INFO, True) - self._room_ids: typing.List[int] = [] + self._room_ids: list[int] = [] self.type: int = 1 self.subbody_ver: int = 1 @@ -148,7 +146,7 @@ def __init__(self, cmd_cype, has_result): class AirConCapabilityQueryParam(AirconParam): def __init__(self): AirconParam.__init__(self, EnumCmdType.AIR_CAPABILITY_QUERY, True) - self._aircons: typing.List[AirCon] = [] + self._aircons: list[AirCon] = [] def generate_subbody(self, s: Encode, config: Config) -> None: s.write1(len(self._aircons)) @@ -174,7 +172,7 @@ def __init__(self): class AirConQueryStatusParam(AirconParam): def __init__(self): super().__init__(EnumCmdType.QUERY_STATUS, True) - self._device: Optional[AirCon] = None + self._device: AirCon | None = None def generate_subbody(self, s: Encode, config: Config) -> None: s.write1(self._device.room_id) @@ -191,9 +189,7 @@ def generate_subbody(self, s: Encode, config: Config) -> None: and dev.fan_direction2 != EnumFanDirection.FIX ): flag = flag | t.FAN_DIRECTION - if dev.bath_room: - flag = flag | t.BREATHE - elif dev.three_d_fresh_allow: + if dev.bath_room or dev.three_d_fresh_allow: flag = flag | t.BREATHE flag = flag | t.HUMIDITY if dev.hum_fresh_air_allow: diff --git a/custom_components/ds_air/ds_air_service/service.py b/custom_components/ds_air/ds_air_service/service.py index 98970aa..a53445d 100644 --- a/custom_components/ds_air/ds_air_service/service.py +++ b/custom_components/ds_air/ds_air_service/service.py @@ -1,14 +1,14 @@ from __future__ import annotations +from collections.abc import Callable import logging import socket -import time -from collections.abc import Callable from threading import Lock, Thread +import time from .config import Config from .ctrl_enum import EnumDevice -from .dao import AirCon, AirConStatus, Room, STATUS_ATTR, Sensor, get_device_by_aircon +from .dao import STATUS_ATTR, AirCon, AirConStatus, Room, Sensor, get_device_by_aircon from .decoder import BaseResult, decoder from .display import display from .param import ( @@ -53,7 +53,7 @@ def do_connect(self): self._s.connect((self._host, self._port)) _log("connected") return True - except socket.error as exc: + except OSError as exc: _log("connected error") _log(str(exc)) return False @@ -243,7 +243,7 @@ def is_ready(self) -> bool: return self._ready def send_msg(self, p: Param): - """send msg to climate gateway""" + """Send msg to climate gateway""" self._socket_client.send(p) def get_rooms(self): diff --git a/custom_components/ds_air/sensor.py b/custom_components/ds_air/sensor.py index 5e9fada..270f2e9 100644 --- a/custom_components/ds_air/sensor.py +++ b/custom_components/ds_air/sensor.py @@ -7,8 +7,8 @@ from homeassistant.helpers.entity_platform import AddEntitiesCallback from .const import DOMAIN, MANUFACTURER -from .descriptions import DsSensorEntityDescription, SENSOR_DESCRIPTORS -from .ds_air_service import Sensor, Service, UNINITIALIZED_VALUE +from .descriptions import SENSOR_DESCRIPTORS, DsSensorEntityDescription +from .ds_air_service import UNINITIALIZED_VALUE, Sensor, Service async def async_setup_entry(