Skip to content

Commit

Permalink
Merge pull request #56 from xrh0905/test
Browse files Browse the repository at this point in the history
一点改进
  • Loading branch information
mypal authored Jul 16, 2023
2 parents 3c6b405 + 7207cbd commit 21c8dbd
Show file tree
Hide file tree
Showing 10 changed files with 298 additions and 154 deletions.
55 changes: 0 additions & 55 deletions custom_components/ds_air/air_quality.py

This file was deleted.

122 changes: 85 additions & 37 deletions custom_components/ds_air/climate.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""
Demo platform that offers a fake climate device.
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 @@ -11,13 +11,22 @@
import voluptuous as vol
from homeassistant.components.climate import ClimateEntity
from homeassistant.components.climate import PLATFORM_SCHEMA
from homeassistant.components.climate.const import (
SUPPORT_TARGET_TEMPERATURE, SUPPORT_FAN_MODE,
""" from homeassistant.components.climate.const import (
SUPPORT_TARGET_TEMPERATURE,
SUPPORT_FAN_MODE,
SUPPORT_SWING_MODE,
SUPPORT_TARGET_HUMIDITY, HVAC_MODE_OFF, HVAC_MODE_HEAT, HVAC_MODE_COOL, HVAC_MODE_HEAT_COOL, HVAC_MODE_AUTO,
SUPPORT_TARGET_HUMIDITY,
HVAC_MODE_OFF, HVAC_MODE_HEAT, HVAC_MODE_COOL, HVAC_MODE_HEAT_COOL, HVAC_MODE_AUTO,
HVAC_MODE_DRY,
HVAC_MODE_FAN_ONLY,
FAN_AUTO, FAN_LOW, FAN_MEDIUM, FAN_HIGH)
FAN_AUTO, FAN_LOW, FAN_MEDIUM, FAN_HIGH) """
from homeassistant.components.climate import (
ClimateEntity,
ClimateEntityFeature,
HVACMode, HVACAction,
PRESET_NONE, PRESET_SLEEP, PRESET_COMFORT,
FAN_AUTO, FAN_LOW, FAN_MEDIUM, FAN_HIGH
)
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import TEMP_CELSIUS, ATTR_TEMPERATURE, CONF_HOST, CONF_PORT
from homeassistant.core import HomeAssistant, Event
Expand All @@ -32,10 +41,9 @@
from .ds_air_service.dao import AirCon, AirConStatus
from .ds_air_service.display import display

SUPPORT_FLAGS = SUPPORT_TARGET_TEMPERATURE | SUPPORT_FAN_MODE | SUPPORT_SWING_MODE \
| SUPPORT_SWING_MODE | SUPPORT_TARGET_HUMIDITY
#FAN_LIST = ['最弱', '稍弱', '中等', '稍强', '最强', '自动']
FAN_LIST = [FAN_LOW, '稍弱', FAN_MEDIUM, '稍强', FAN_HIGH, FAN_AUTO]
_SUPPORT_FLAGS = ClimateEntityFeature.TARGET_TEMPERATURE | ClimateEntityFeature.FAN_MODE | ClimateEntityFeature.PRESET_MODE
# | ClimateEntityFeature.SWING_MODE | ClimateEntityFeature.TARGET_HUMIDITY
FAN_LIST = [ FAN_LOW, '稍弱', FAN_MEDIUM, '稍强', FAN_HIGH, FAN_AUTO]
SWING_LIST = ['➡️', '↘️', '⬇️', '↙️', '⬅️', '↔️', '🔄']

PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
Expand Down Expand Up @@ -88,7 +96,7 @@ async def listener(event: Event):


class DsAir(ClimateEntity):
"""Representation of a demo climate device."""
"""Representation of a Daikin climate device."""

def __init__(self, aircon: AirCon):
_log('create aircon:')
Expand Down Expand Up @@ -186,7 +194,10 @@ def target_humidity(self):
@property
def hvac_action(self):
"""Return current operation ie. heat, cool, idle."""
return None
if self._device_info.status.switch == EnumControl.Switch.OFF:
return HVACAction.OFF
else:
return EnumControl.get_action_name(self._device_info.status.mode.value)

@property
def hvac_mode(self) -> str:
Expand All @@ -195,7 +206,7 @@ def hvac_mode(self) -> str:
Need to be one of HVAC_MODE_*.
"""
if self._device_info.status.switch == EnumControl.Switch.OFF:
return HVAC_MODE_OFF
return HVACMode.OFF
else:
return EnumControl.get_mode_name(self._device_info.status.mode.value)

Expand All @@ -205,18 +216,16 @@ def hvac_modes(self):
li = []
aircon = self._device_info
if aircon.cool_mode:
li.append(HVAC_MODE_COOL)
li.append(HVACMode.COOL)
if aircon.heat_mode or aircon.pre_heat_mode:
li.append(HVAC_MODE_HEAT)
li.append(HVACMode.HEAT)
if aircon.auto_dry_mode or aircon.dry_mode or aircon.more_dry_mode:
li.append(HVAC_MODE_DRY)
li.append(HVACMode.DRY)
if aircon.ventilation_mode:
li.append(HVAC_MODE_FAN_ONLY)
if aircon.relax_mode or aircon.auto_mode:
li.append(HVAC_MODE_AUTO)
if aircon.sleep_mode:
li.append(HVAC_MODE_HEAT_COOL)
li.append(HVAC_MODE_OFF)
li.append(HVACMode.FAN_ONLY)
if aircon.relax_mode or aircon.sleep_mode or aircon.auto_mode:
li.append(HVACMode.AUTO)
li.append(HVACMode.OFF)
return li

@property
Expand All @@ -238,7 +247,7 @@ def target_temperature(self):
@property
def target_temperature_step(self):
"""Return the supported step of target temperature."""
return 1
return 0.5

@property
def target_temperature_high(self):
Expand All @@ -264,15 +273,27 @@ def preset_mode(self) -> Optional[str]:
Requires SUPPORT_PRESET_MODE.
"""
return None
if self._device_info.status.mode == EnumControl.Mode.SLEEP:
return PRESET_SLEEP
elif self._device_info.status.mode == EnumControl.Mode.RELAX:
return PRESET_COMFORT
else:
return PRESET_NONE

@property
def preset_modes(self) -> Optional[List[str]]:
"""Return a list of available preset modes.
Requires SUPPORT_PRESET_MODE.
"""
return None
result = []
aircon = self._device_info
if aircon.sleep_mode:
result.append(PRESET_SLEEP)
if aircon.relax_mode:
result.append(PRESET_COMFORT)
result.append(PRESET_NONE)
return result

@property
def is_aux_heat(self):
Expand Down Expand Up @@ -312,8 +333,8 @@ def set_temperature(self, **kwargs):
new_status = AirConStatus()
if status.switch == EnumControl.Switch.ON \
and status.mode not in [EnumControl.Mode.VENTILATION, EnumControl.Mode.MOREDRY]:
status.setted_temp = round(kwargs.get(ATTR_TEMPERATURE)) * 10
new_status.setted_temp = round(kwargs.get(ATTR_TEMPERATURE)) * 10
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
Service.control(self._device_info, new_status)
self.schedule_update_ha_state()
Expand Down Expand Up @@ -347,7 +368,7 @@ def set_hvac_mode(self, hvac_mode: str) -> None:
aircon = self._device_info
status = aircon.status
new_status = AirConStatus()
if hvac_mode == HVAC_MODE_OFF:
if hvac_mode == HVACMode.OFF:
status.switch = EnumControl.Switch.OFF
new_status.switch = EnumControl.Switch.OFF
from .ds_air_service.service import Service
Expand All @@ -357,29 +378,29 @@ def set_hvac_mode(self, hvac_mode: str) -> None:
new_status.switch = EnumControl.Switch.ON
m = EnumControl.Mode
mode = None
if hvac_mode == HVAC_MODE_COOL:
if hvac_mode == HVACMode.COOL:
mode = m.COLD
elif hvac_mode == HVAC_MODE_HEAT:
elif hvac_mode == HVACMode.HEAT:
if aircon.heat_mode:
mode = m.HEAT
else:
mode = m.PREHEAT
elif hvac_mode == HVAC_MODE_DRY:
elif hvac_mode == HVACMode.DRY:
if aircon.auto_dry_mode:
mode = m.AUTODRY
elif aircon.more_dry_mode:
mode = m.MOREDRY
else:
mode = m.DRY
elif hvac_mode == HVAC_MODE_FAN_ONLY:
elif hvac_mode == HVACMode.FAN_ONLY:
mode = m.VENTILATION
elif hvac_mode == HVAC_MODE_AUTO:
elif hvac_mode == HVACMode.AUTO:
if aircon.auto_mode:
mode = m.AUTO
else:
elif aircon.relax_mode:
mode = m.RELAX
elif hvac_mode == HVAC_MODE_HEAT_COOL:
mode = m.SLEEP
else:
mode = m.SLEEP
status.mode = mode
new_status.mode = mode
from .ds_air_service.service import Service
Expand All @@ -400,7 +421,28 @@ def set_swing_mode(self, swing_mode):
self.schedule_update_ha_state()

def set_preset_mode(self, preset_mode: str) -> None:
pass
aircon = self._device_info
status = aircon.status
new_status = AirConStatus()
m = EnumControl.Mode
mode = None
if preset_mode == PRESET_NONE:
if aircon.auto_mode:
mode = m.AUTO
elif aircon.relax_mode:
mode = m.RELAX
else:
mode = m.COLD
else:
if preset_mode == PRESET_SLEEP:
mode = m.SLEEP
elif preset_mode == PRESET_COMFORT:
mode = m.RELAX
status.mode = mode
new_status.mode = mode
from .ds_air_service.service import Service
Service.control(self._device_info, new_status)
self.schedule_update_ha_state()

def turn_aux_heat_on(self) -> None:
pass
Expand All @@ -411,6 +453,12 @@ def turn_aux_heat_off(self) -> None:
@property
def supported_features(self) -> int:
"""Return the list of supported features."""
SUPPORT_FLAGS = _SUPPORT_FLAGS
aircon = self._device_info
if self._device_info.status.fan_direction1.value > 0:
SUPPORT_FLAGS = SUPPORT_FLAGS | ClimateEntityFeature.SWING_MODE
if aircon.relax_mode:
SUPPORT_FLAGS = SUPPORT_FLAGS | ClimateEntityFeature.TARGET_HUMIDITY
return SUPPORT_FLAGS

@property
Expand All @@ -436,7 +484,7 @@ def device_info(self) -> Optional[DeviceInfo]:
return {
"identifiers": {(DOMAIN, self.unique_id)},
"name": "空调%s" % self._name,
"manufacturer": "DAIKIN INDUSTRIES, Ltd."
"manufacturer": "Daikin Industries, Ltd."
}

@property
Expand Down
Loading

0 comments on commit 21c8dbd

Please sign in to comment.