Skip to content

Commit

Permalink
ruff check fix
Browse files Browse the repository at this point in the history
  • Loading branch information
caibinqing committed Sep 5, 2024
1 parent 6b9cffa commit 6b3a1c4
Show file tree
Hide file tree
Showing 11 changed files with 59 additions and 69 deletions.
4 changes: 1 addition & 3 deletions custom_components/ds_air/__init__.py
Original file line number Diff line number Diff line change
@@ -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/
"""

Expand All @@ -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 = [
Expand Down
33 changes: 15 additions & 18 deletions custom_components/ds_air/climate.py
Original file line number Diff line number Diff line change
@@ -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/
Expand All @@ -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 (
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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:
Expand Down Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions custom_components/ds_air/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from typing import Any

import voluptuous as vol

from homeassistant.components.sensor import SensorDeviceClass
from homeassistant.config_entries import (
ConfigEntry,
Expand Down
1 change: 0 additions & 1 deletion custom_components/ds_air/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

from .ds_air_service import EnumControl


DOMAIN = "ds_air"
CONF_GW = "gw"
DEFAULT_HOST = "192.168.1."
Expand Down
3 changes: 2 additions & 1 deletion custom_components/ds_air/descriptions.py
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
2 changes: 1 addition & 1 deletion custom_components/ds_air/ds_air_service/__init__.py
Original file line number Diff line number Diff line change
@@ -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
9 changes: 4 additions & 5 deletions custom_components/ds_air/ds_air_service/dao.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import time
from typing import Optional

from .config import Config
from .ctrl_enum import (
EnumControl,
EnumDevice,
Expand All @@ -9,7 +9,6 @@
EnumOutDoorRunCond,
EnumSwitch,
)
from .config import Config


class Device:
Expand Down Expand Up @@ -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()
49 changes: 24 additions & 25 deletions custom_components/ds_air/ds_air_service/decoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -585,15 +585,15 @@ def __init__(self, cmd_id: int, target: EnumDevice):
)

def load_bytes(self, b: bytes, config: Config) -> None:
"""todo"""
"""Todo"""


class QueryScheduleIDResult(BaseResult):
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):
Expand All @@ -619,26 +619,26 @@ 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):
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):
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):
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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):
Expand Down
12 changes: 4 additions & 8 deletions custom_components/ds_air/ds_air_service/param.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import struct
import typing
from typing import Optional

from .base_bean import BaseBean
from .config import Config
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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))
Expand All @@ -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)
Expand All @@ -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:
Expand Down
10 changes: 5 additions & 5 deletions custom_components/ds_air/ds_air_service/service.py
Original file line number Diff line number Diff line change
@@ -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 (
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand Down
4 changes: 2 additions & 2 deletions custom_components/ds_air/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 6b3a1c4

Please sign in to comment.