Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

重构,支持多网关 #82

Open
wants to merge 15 commits into
base: test
Choose a base branch
from
Prev Previous commit
Next Next commit
make ds_air_service as package
caibinqing committed Sep 5, 2024
commit efeacc82549adf8e6832716d3cea4d25c4cf5b6c
6 changes: 3 additions & 3 deletions custom_components/ds_air/__init__.py
Original file line number Diff line number Diff line change
@@ -11,7 +11,7 @@

from .hass_inst import GetHass
from .const import CONF_GW, DEFAULT_HOST, DEFAULT_PORT, DEFAULT_GW, DOMAIN
from .ds_air_service.config import Config
from .ds_air_service import Config

_LOGGER = logging.getLogger(__name__)
PLATFORMS = ["climate", "sensor"]
@@ -46,7 +46,7 @@ async def async_setup_entry(

Config.is_c611 = gw == DEFAULT_GW

from .ds_air_service.service import Service
from .ds_air_service import Service
await hass.async_add_executor_job(Service.init, host, port, scan_interval)
await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
entry.async_on_unload(entry.add_update_listener(update_listener))
@@ -59,7 +59,7 @@ async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
if hass.data[DOMAIN].get("listener") is not None:
hass.data[DOMAIN].get("listener")()
unload_ok = await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
from .ds_air_service.service import Service
from .ds_air_service import Service
Service.destroy()

return unload_ok
26 changes: 13 additions & 13 deletions custom_components/ds_air/climate.py
Original file line number Diff line number Diff line change
@@ -26,10 +26,10 @@
from homeassistant.helpers.event import async_track_state_change_event

from .const import DOMAIN
from .ds_air_service.config import Config
from .ds_air_service.ctrl_enum import EnumControl
from .ds_air_service.dao import AirCon, AirConStatus
from .ds_air_service.display import display
from .ds_air_service import Config
from .ds_air_service import EnumControl
from .ds_air_service import AirCon, AirConStatus
from .ds_air_service import display

_SUPPORT_FLAGS = ClimateEntityFeature.TARGET_TEMPERATURE | ClimateEntityFeature.FAN_MODE | ClimateEntityFeature.PRESET_MODE
# | ClimateEntityFeature.SWING_MODE | ClimateEntityFeature.TARGET_HUMIDITY
@@ -56,7 +56,7 @@ async def async_setup_entry(
) -> None:
"""Set up the climate devices."""

from .ds_air_service.service import Service
from .ds_air_service import Service
climates = []
for aircon in Service.get_aircons():
climates.append(DsAir(aircon))
@@ -107,7 +107,7 @@ def __init__(self, aircon: AirCon):
self._link_cur_humi = False
self._cur_temp = None
self._cur_humi = None
from .ds_air_service.service import Service
from .ds_air_service import Service
Service.register_status_hook(aircon, self._status_change_hook)

async def async_added_to_hass(self) -> None:
@@ -330,7 +330,7 @@ def set_temperature(self, **kwargs):
and status.mode not in [EnumControl.Mode.VENTILATION, EnumControl.Mode.MOREDRY]:
status.setted_temp = round(kwargs.get(ATTR_TEMPERATURE) * 10.0)
new_status.setted_temp = round(kwargs.get(ATTR_TEMPERATURE) * 10.0)
from .ds_air_service.service import Service
from .ds_air_service import Service
Service.control(self._device_info, new_status)
self.schedule_update_ha_state()

@@ -342,7 +342,7 @@ def set_humidity(self, humidity):
and status.mode in [EnumControl.Mode.RELAX, EnumControl.Mode.SLEEP]:
status.humidity = EnumControl.Humidity(humidity)
new_status.humidity = EnumControl.Humidity(humidity)
from .ds_air_service.service import Service
from .ds_air_service import Service
Service.control(self._device_info, new_status)
self.schedule_update_ha_state()

@@ -354,7 +354,7 @@ def set_fan_mode(self, fan_mode):
and status.mode not in [EnumControl.Mode.MOREDRY, EnumControl.Mode.SLEEP]:
status.air_flow = EnumControl.get_air_flow_enum(fan_mode)
new_status.air_flow = EnumControl.get_air_flow_enum(fan_mode)
from .ds_air_service.service import Service
from .ds_air_service import Service
Service.control(self._device_info, new_status)
self.schedule_update_ha_state()

@@ -366,7 +366,7 @@ def set_hvac_mode(self, hvac_mode: str) -> None:
if hvac_mode == HVACMode.OFF:
status.switch = EnumControl.Switch.OFF
new_status.switch = EnumControl.Switch.OFF
from .ds_air_service.service import Service
from .ds_air_service import Service
Service.control(self._device_info, new_status)
else:
status.switch = EnumControl.Switch.ON
@@ -398,7 +398,7 @@ def set_hvac_mode(self, hvac_mode: str) -> None:
mode = m.SLEEP
status.mode = mode
new_status.mode = mode
from .ds_air_service.service import Service
from .ds_air_service import Service
Service.control(self._device_info, new_status)
self.schedule_update_ha_state()

@@ -411,7 +411,7 @@ def set_swing_mode(self, swing_mode):
new_status.fan_direction1 = self._device_info.status.fan_direction1
status.fan_direction2 = EnumControl.get_fan_direction_enum(swing_mode)
new_status.fan_direction2 = EnumControl.get_fan_direction_enum(swing_mode)
from .ds_air_service.service import Service
from .ds_air_service import Service
Service.control(self._device_info, new_status)
self.schedule_update_ha_state()

@@ -435,7 +435,7 @@ def set_preset_mode(self, preset_mode: str) -> None:
mode = m.RELAX
status.mode = mode
new_status.mode = mode
from .ds_air_service.service import Service
from .ds_air_service import Service
Service.control(self._device_info, new_status)
self.schedule_update_ha_state()

2 changes: 1 addition & 1 deletion custom_components/ds_air/config_flow.py
Original file line number Diff line number Diff line change
@@ -19,7 +19,7 @@
from homeassistant.data_entry_flow import FlowResult

from .const import CONF_GW, DEFAULT_GW, DEFAULT_HOST, DEFAULT_PORT, DOMAIN, GW_LIST
from .ds_air_service.service import Service
from .ds_air_service import Service
from .hass_inst import GetHass

_LOGGER = logging.getLogger(__name__)
5 changes: 5 additions & 0 deletions custom_components/ds_air/ds_air_service/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from .config import Config
from .ctrl_enum import EnumControl
from .dao import AirCon, AirConStatus, Sensor, UNINITIALIZED_VALUE
from .display import display
from .service import Service
4 changes: 2 additions & 2 deletions custom_components/ds_air/sensor.py
Original file line number Diff line number Diff line change
@@ -6,8 +6,8 @@
from homeassistant.helpers.entity_platform import AddEntitiesCallback

from .const import DOMAIN, DsSensorEntityDescription, SENSOR_DESCRIPTORS
from .ds_air_service.dao import Sensor, UNINITIALIZED_VALUE
from .ds_air_service.service import Service
from .ds_air_service import Sensor, UNINITIALIZED_VALUE
from .ds_air_service import Service


async def async_setup_entry(