Skip to content

Commit 3a721d5

Browse files
authored
Merge pull request #47 from mypal/test
version 1.3.3
2 parents 6838f05 + c469979 commit 3a721d5

File tree

8 files changed

+133
-53
lines changed

8 files changed

+133
-53
lines changed

custom_components/ds_air/__init__.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ def _log(s: str):
2121
for i in s.split("\n"):
2222
_LOGGER.debug(i)
2323

24-
2524
def setup(hass, config):
2625
hass.data[DOMAIN] = {}
2726
GetHass.set_hass(hass)
@@ -48,7 +47,7 @@ async def async_setup_entry(
4847

4948
from .ds_air_service.service import Service
5049
await hass.async_add_executor_job(Service.init, host, port, scan_interval)
51-
hass.config_entries.async_setup_platforms(entry, PLATFORMS)
50+
await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
5251
entry.async_on_unload(entry.add_update_listener(update_listener))
5352

5453
return True

custom_components/ds_air/climate.py

Lines changed: 50 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616
SUPPORT_SWING_MODE,
1717
SUPPORT_TARGET_HUMIDITY, HVAC_MODE_OFF, HVAC_MODE_HEAT, HVAC_MODE_COOL, HVAC_MODE_HEAT_COOL, HVAC_MODE_AUTO,
1818
HVAC_MODE_DRY,
19-
HVAC_MODE_FAN_ONLY)
19+
HVAC_MODE_FAN_ONLY,
20+
FAN_AUTO, FAN_LOW, FAN_MEDIUM, FAN_HIGH)
2021
from homeassistant.config_entries import ConfigEntry
2122
from homeassistant.const import TEMP_CELSIUS, ATTR_TEMPERATURE, CONF_HOST, CONF_PORT
2223
from homeassistant.core import HomeAssistant, Event
@@ -33,7 +34,8 @@
3334

3435
SUPPORT_FLAGS = SUPPORT_TARGET_TEMPERATURE | SUPPORT_FAN_MODE | SUPPORT_SWING_MODE \
3536
| SUPPORT_SWING_MODE | SUPPORT_TARGET_HUMIDITY
36-
FAN_LIST = ['最弱', '稍弱', '中等', '稍强', '最强', '自动']
37+
#FAN_LIST = ['最弱', '稍弱', '中等', '稍强', '最强', '自动']
38+
FAN_LIST = [FAN_LOW, '稍弱', FAN_MEDIUM, '稍强', FAN_HIGH, FAN_AUTO]
3739
SWING_LIST = ['➡️', '↘️', '⬇️', '↙️', '⬅️', '↔️', '🔄']
3840

3941
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
@@ -43,50 +45,67 @@
4345

4446
_LOGGER = logging.getLogger(__name__)
4547

46-
4748
def _log(s: str):
4849
s = str(s)
4950
for i in s.split("\n"):
5051
_LOGGER.debug(i)
5152

52-
5353
async def async_setup_entry(
5454
hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
5555
) -> None:
56-
"""Set up the Demo climate devices."""
56+
"""Set up the climate devices."""
5757

5858
from .ds_air_service.service import Service
5959
climates = []
6060
for aircon in Service.get_aircons():
6161
climates.append(DsAir(aircon))
6262
async_add_entities(climates)
6363
link = entry.options.get("link")
64-
sensor_map = {}
64+
sensor_temp_map = {}
65+
sensor_humi_map = {}
6566
if link is not None:
6667
for i in link:
67-
if i.get("sensor") is not None:
68+
if i.get("sensor_temp") is not None:
6869
climate = None
6970
for j in climates:
7071
if i.get("climate") == j.name:
7172
climate = j
7273
break
73-
if sensor_map.get(i.get("sensor")) is not None:
74-
sensor_map[i.get("sensor")].append(climate)
74+
if sensor_temp_map.get(i.get("sensor_temp")) is not None:
75+
sensor_temp_map[i.get("sensor_temp")].append(climate)
7576
else:
76-
sensor_map[i.get("sensor")] = [climate]
77+
sensor_temp_map[i.get("sensor_temp")] = [climate]
78+
if i.get("sensor_humi") is not None:
79+
climate = None
80+
for j in climates:
81+
if i.get("climate") == j.name:
82+
climate = j
83+
break
84+
if sensor_humi_map.get(i.get("sensor_humi")) is not None:
85+
sensor_humi_map[i.get("sensor_humi")].append(climate)
86+
else:
87+
sensor_humi_map[i.get("sensor_humi")] = [climate]
7788

78-
async def listener(event: Event):
79-
for climate in sensor_map[event.data.get("entity_id")]:
80-
climate.update_cur_temp(event.data.get("new_state").state)
89+
async def listner(event: Event):
90+
if event.data.get("entity_id") in sensor_temp_map:
91+
for climate in sensor_temp_map[event.data.get("entity_id")]:
92+
climate.update_cur_temp(event.data.get("new_state").state)
93+
elif event.data.get("entity_id") in sensor_humi_map:
94+
for climate in sensor_humi_map[event.data.get("entity_id")]:
95+
climate.update_cur_humi(event.data.get("new_state").state)
8196

82-
remove_listener = async_track_state_change_event(hass, list(sensor_map.keys()), listener)
97+
remove_listener = async_track_state_change_event(hass, list(sensor_temp_map.keys()) + list(sensor_humi_map.keys()), listner)
8398
hass.data[DOMAIN]["listener"] = remove_listener
84-
for entity_id in sensor_map.keys():
99+
for entity_id in sensor_temp_map.keys():
85100
state = hass.states.get(entity_id)
86101
if state is not None:
87-
for climate in sensor_map[entity_id]:
102+
for climate in sensor_temp_map[entity_id]:
88103
climate.update_cur_temp(state.state)
89-
104+
for entity_id in sensor_humi_map.keys():
105+
state = hass.states.get(entity_id)
106+
if state is not None:
107+
for climate in sensor_humi_map[entity_id]:
108+
climate.update_cur_humi(state.state)
90109

91110
class DsAir(ClimateEntity):
92111
"""Representation of a demo climate device."""
@@ -100,7 +119,9 @@ def __init__(self, aircon: AirCon):
100119
self._device_info = aircon
101120
self._unique_id = aircon.unique_id
102121
self._link_cur_temp = False
122+
self._link_cur_humi = False
103123
self._cur_temp = None
124+
self._cur_humi = None
104125
from .ds_air_service.service import Service
105126
Service.register_status_hook(aircon, self._status_change_hook)
106127

@@ -144,6 +165,14 @@ def update_cur_temp(self, value):
144165
"""Ignore"""
145166
self.schedule_update_ha_state()
146167

168+
def update_cur_humi(self, value):
169+
self._link_cur_humi = value is not None
170+
try:
171+
self._cur_humi = int(float(value))
172+
except ValueError:
173+
"""Ignore"""
174+
self.schedule_update_ha_state()
175+
147176
@property
148177
def should_poll(self):
149178
"""Return the polling state."""
@@ -234,7 +263,10 @@ def target_temperature_low(self):
234263
@property
235264
def current_humidity(self):
236265
"""Return the current humidity."""
237-
return None
266+
if self._link_cur_humi:
267+
return self._cur_humi
268+
else:
269+
return None
238270

239271
@property
240272
def preset_mode(self) -> Optional[str]:

custom_components/ds_air/config_flow.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -77,23 +77,25 @@ async def async_step_user(
7777
def async_get_options_flow(
7878
config_entry: ConfigEntry,
7979
) -> DsAirOptionsFlowHandler:
80-
"""Options callback for AccuWeather."""
80+
"""Options callback for DS-AIR."""
8181
return DsAirOptionsFlowHandler(config_entry)
8282

8383

8484
class DsAirOptionsFlowHandler(config_entries.OptionsFlow):
85-
"""Config flow options for AccuWeather."""
85+
"""Config flow options for sensors binding."""
8686

8787
def __init__(self, entry: ConfigEntry) -> None:
88-
"""Initialize AccuWeather options flow."""
88+
"""Initialize DSAir options flow."""
8989
self.config_entry = entry
9090
self._len = 3
9191
self._cur = 0
9292
hass: HomeAssistant = GetHass.get_hash()
9393
self._climates = list(map(lambda state: state.alias, Service.get_aircons()))
9494
sensors = hass.states.async_all("sensor")
95-
self._sensors = list(map(lambda state: state.entity_id,
95+
self._sensors_temp = list(map(lambda state: state.entity_id,
9696
filter(lambda state: state.attributes.get("device_class") == "temperature", sensors)))
97+
self._sensors_humi = list(map(lambda state: state.entity_id,
98+
filter(lambda state: state.attributes.get("device_class") == "humidity", sensors)))
9799
self._config_data = []
98100

99101
async def async_step_init(
@@ -111,7 +113,8 @@ async def async_step_user(
111113
if user_input is not None:
112114
self._config_data.append({
113115
"climate": user_input.get("climate"),
114-
"sensor": user_input.get("sensor")
116+
"sensor_temp": user_input.get("sensor_temp"),
117+
"sensor_humi": user_input.get("sensor_humi")
115118
})
116119
if self._cur == self._len:
117120
return self.async_create_entry(title="", data={"link": self._config_data})
@@ -124,7 +127,8 @@ async def async_step_user(
124127
"climate",
125128
default=self._climates[self._cur]
126129
): vol.In([self._climates[self._cur]]),
127-
vol.Optional("sensor"): vol.In(self._sensors)
130+
vol.Optional("sensor_temp"): vol.In(self._sensors_temp),
131+
vol.Optional("sensor_humi"): vol.In(self._sensors_humi)
128132
}
129133
)
130134
)

custom_components/ds_air/const.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from homeassistant.const import TEMP_CELSIUS, PERCENTAGE, CONCENTRATION_MICROGRAMS_PER_CUBIC_METER, \
22
CONCENTRATION_PARTS_PER_MILLION, CONCENTRATION_MILLIGRAMS_PER_CUBIC_METER, DEVICE_CLASS_HUMIDITY, \
3-
DEVICE_CLASS_TEMPERATURE, DEVICE_CLASS_CO2
3+
DEVICE_CLASS_TEMPERATURE, DEVICE_CLASS_CO2, DEVICE_CLASS_PM25
44

55
from .ds_air_service.ctrl_enum import EnumSensor
66

@@ -13,7 +13,7 @@
1313
SENSOR_TYPES = {
1414
"temp": [TEMP_CELSIUS, None, DEVICE_CLASS_TEMPERATURE, 10],
1515
"humidity": [PERCENTAGE, None, DEVICE_CLASS_HUMIDITY, 10],
16-
"pm25": [CONCENTRATION_MICROGRAMS_PER_CUBIC_METER, None, None, 1],
16+
"pm25": [CONCENTRATION_MICROGRAMS_PER_CUBIC_METER, None, DEVICE_CLASS_PM25, 1],
1717
"co2": [CONCENTRATION_PARTS_PER_MILLION, None, DEVICE_CLASS_CO2, 1],
1818
"tvoc": [CONCENTRATION_MILLIGRAMS_PER_CUBIC_METER, None, None, 100],
1919
"voc": [None, None, None, EnumSensor.Voc],

custom_components/ds_air/ds_air_service/ctrl_enum.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
from enum import Enum, IntEnum
22

33
from homeassistant.components.climate.const import \
4-
HVAC_MODE_COOL, HVAC_MODE_FAN_ONLY, HVAC_MODE_HEAT, HVAC_MODE_DRY, HVAC_MODE_AUTO, HVAC_MODE_HEAT_COOL
4+
HVAC_MODE_COOL, HVAC_MODE_FAN_ONLY, HVAC_MODE_HEAT, HVAC_MODE_DRY, HVAC_MODE_AUTO, HVAC_MODE_HEAT_COOL, \
5+
FAN_AUTO, FAN_LOW, FAN_MEDIUM, FAN_HIGH
56

67

78
class EnumCmdType(IntEnum):
@@ -235,8 +236,8 @@ class AirFlow(IntEnum):
235236
AUTO = 5
236237

237238

238-
_AIR_FLOW_NAME_LIST = ['最弱', '稍弱', '中等', '稍强', '最强', '自动']
239-
239+
#_AIR_FLOW_NAME_LIST = ['最弱', '稍弱', '中等', '稍强', '最强', '自动']
240+
_AIR_FLOW_NAME_LIST = [FAN_LOW, '稍弱', FAN_MEDIUM, '稍强', FAN_HIGH, FAN_AUTO]
240241

241242
class Breathe(IntEnum):
242243
CLOSE = 0

custom_components/ds_air/manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@
55
"dependencies": [],
66
"codeowners": [],
77
"requirements": [],
8-
"version": "1.3.2",
8+
"version": "1.3.3",
99
"config_flow": true
1010
}

custom_components/ds_air/translations/en.json

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,41 +2,42 @@
22
"config": {
33
"step": {
44
"user": {
5-
"title": "\u91d1\u5236\u7a7a\u6c14",
6-
"description": "\u672c\u63d2\u4ef6\u652f\u6301\u5927\u91d1DTA117B611/DTA117C611\u4e24\u6b3e\u7a7a\u8c03\u7f51\u5173",
5+
"title": "DS-AIR",
6+
"description": "Support DTA117B611/DTA117C611",
77
"data": {
8-
"host": "host",
9-
"port": "port",
10-
"gw": "\u7f51\u5173\u578b\u53f7",
11-
"scan_interval": "\u4f20\u611f\u5668\u66f4\u65b0\u9891\u7387\uff08\u5355\u4f4d\uff1a\u5206\u949f\uff09",
12-
"sensors": "\u662f\u5426\u6709\u4f20\u611f\u5668",
13-
"temp": "\u521b\u5efatemperature\u5b9e\u4f53",
14-
"humidity": "\u521b\u5efahumidity\u5b9e\u4f53",
15-
"pm25": "\u521b\u5efapm25\u5b9e\u4f53",
16-
"co2": "\u521b\u5efaco2\u5b9e\u4f53",
17-
"tvoc": "\u521b\u5efatvoc\u5b9e\u4f53",
18-
"voc": "\u521b\u5efavoc\u5b9e\u4f53",
19-
"hcho": "\u521b\u5efahcho\u5b9e\u4f53"
8+
"host": "Host",
9+
"port": "Port",
10+
"gw": "Gateway model",
11+
"scan_interval": "Sensor update frequency (minutes)",
12+
"sensors": "Has sensor",
13+
"temp": "Create Temperature entity",
14+
"humidity": "Create Humidity entity",
15+
"pm25": "Create PM2.5 entity",
16+
"co2": "Create CO2 entity",
17+
"tvoc": "Create TVOC entity",
18+
"voc": "Create VOC entity",
19+
"hcho": "Create HCHO entity"
2020
}
2121
}
2222
},
2323
"error": {
2424
},
2525
"abort": {
26-
"single_instance_allowed": "\u53ea\u5141\u8bb8\u521b\u5efa\u4e00\u4e2a"
26+
"single_instance_allowed": "Only one instance is allowed."
2727
},
28-
"flow_title": "\u91d1\u5236\u7a7a\u6c14"
28+
"flow_title": "DS-AIR"
2929
},
3030
"options": {
3131
"step": {
3232
"user": {
33-
"title": "\u6e29\u5ea6\u4f20\u611f\u5668\u5173\u8054",
34-
"description": "\u53ef\u4ee5\u4e3a\u7a7a\u8c03\u5173\u8054\u6e29\u5ea6\u4f20\u611f\u5668",
33+
"title": "Binding sensors",
34+
"description": "Bind sensors to climate",
3535
"data": {
36-
"climate": "climate name",
37-
"sensor": "sensor entity_id"
36+
"climate": "Climate name",
37+
"sensor_temp": "Temperature sensor entity_id",
38+
"sensor_humi": "Humidity sensor entity_id"
3839
}
3940
}
4041
}
4142
}
42-
}
43+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
{
2+
"config": {
3+
"step": {
4+
"user": {
5+
"title": "金制空气",
6+
"description": "本插件支持大金DTA117B611/DTA117C611两款空调网关",
7+
"data": {
8+
"host": "网关IP",
9+
"port": "网关端口",
10+
"gw": "网关型号",
11+
"scan_interval": "传感器更新频率(单位:分钟)",
12+
"sensors": "是否有传感器",
13+
"temp": "创建温度实体",
14+
"humidity": "创建湿度实体",
15+
"pm25": "创建PM2.5实体",
16+
"co2": "创建CO2实体",
17+
"tvoc": "创建tvoc实体",
18+
"voc": "创建voc实体",
19+
"hcho": "创建hcho实体"
20+
}
21+
}
22+
},
23+
"error": {
24+
},
25+
"abort": {
26+
"single_instance_allowed": "只允许创建一个实例"
27+
},
28+
"flow_title": "金制空气"
29+
},
30+
"options": {
31+
"step": {
32+
"user": {
33+
"title": "传感器关联",
34+
"description": "为空调关联温湿度传感器",
35+
"data": {
36+
"climate": "空调名称",
37+
"sensor_temp": "温度传感器实体ID",
38+
"sensor_humi": "湿度传感器实体ID"
39+
}
40+
}
41+
}
42+
}
43+
}

0 commit comments

Comments
 (0)