Skip to content

Commit 23f75ab

Browse files
authored
Merge pull request #59 from rleschuk/main
версия 0.3.12
2 parents b75e6a6 + ff40d97 commit 23f75ab

File tree

9 files changed

+26
-78
lines changed

9 files changed

+26
-78
lines changed

custom_components/haier_evo/api.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ def save_tokens(self) -> None:
215215
except Exception as e:
216216
_LOGGER.error(f"Failed to save tokens file: {e}")
217217
else:
218-
_LOGGER.info(f"Saved tokens file: {filename}")
218+
_LOGGER.debug(f"Saved tokens file: {filename}")
219219

220220
def clear_tokens(self) -> None:
221221
self.token = None
@@ -284,7 +284,7 @@ def make_request(self, method: str, url: str, **kwargs) -> requests.Response:
284284
def auth_login(self) -> AuthResponse:
285285
try:
286286
path = urljoin(C.API_PATH, C.API_LOGIN)
287-
_LOGGER.info(f"Logging in to {path} with email {self.email}")
287+
_LOGGER.debug(f"Logging in to {path} with email {self.email}")
288288
response = AuthResponse(self.make_request('POST', path, data={
289289
'email': self.email,
290290
'password': self.password
@@ -418,7 +418,7 @@ def pull_device_data(self, device_mac: str) -> dict:
418418
headers={"X-Auth-token": self.token},
419419
timeout=C.API_TIMEOUT
420420
)
421-
_LOGGER.info(f"Update device {device_mac} status code: {response.status_code}")
421+
_LOGGER.debug(f"Update device {device_mac} status code: {response.status_code}")
422422
_LOGGER.debug(response.text)
423423
response.raise_for_status()
424424
data = response.json()
@@ -542,12 +542,12 @@ def connect(self) -> None:
542542
try:
543543
self.socket_status = SocketStatus.INITIALIZING
544544
self._init_ws()
545-
self.socket_app.run_forever(ping_interval=30, ping_timeout=2)
545+
self.socket_app.run_forever(ping_interval=10, ping_timeout=2)
546546
except WebSocketException: # socket is already opened
547547
pass
548548
except Exception as e:
549549
_LOGGER.error(f"Error connecting to websocket: {e}")
550-
_LOGGER.info("Connection stoped")
550+
_LOGGER.debug("Connection stoped")
551551

552552
def connect_in_thread(self) -> None:
553553
self.socket_thread = thread = threading.Thread(target=self.connect)

custom_components/haier_evo/binary_sensor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ async def async_setup_entry(hass: HomeAssistant, config_entry, async_add_entitie
1717

1818

1919
class HaierBinarySensor(BinarySensorEntity):
20-
# _attr_should_poll = False
20+
_attr_should_poll = False
2121

2222
def __init__(self, device: api.HaierDevice) -> None:
2323
self._device = weakref.proxy(device)

custom_components/haier_evo/config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def _load_config_file(self) -> None:
5050
_LOGGER.error(f"Failed to load config: {e}")
5151
self._config = {}
5252
else:
53-
_LOGGER.info("Loaded device config %s", fname)
53+
_LOGGER.debug("Loaded device config %s", fname)
5454

5555
def to_dict(self) -> dict:
5656
return {

custom_components/haier_evo/devices/HEC07HRC03R.yaml

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,4 @@
11
attributes:
2-
- name: mode
3-
id: "5"
4-
mappings:
5-
- haier: "0"
6-
value: "auto"
7-
- haier: "1"
8-
value: "cool"
9-
- haier: "2"
10-
value: "dry"
11-
- haier: "4"
12-
value: "heat"
132
- name: swing_mode
143
id: "8"
154
mappings:

custom_components/haier_evo/devices/HEC09HRC03R.yaml

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,4 @@
11
attributes:
2-
- name: mode
3-
id: "5"
4-
mappings:
5-
- haier: "0"
6-
value: "auto"
7-
- haier: "1"
8-
value: "cool"
9-
- haier: "2"
10-
value: "dry"
11-
- haier: "4"
12-
value: "heat"
132
- name: swing_mode
143
id: "8"
154
mappings:

custom_components/haier_evo/manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@
99
"iot_class": "cloud_polling",
1010
"issue_tracker": "https://github.com/and7ey/haier_evo/issues",
1111
"requirements": ["requests"],
12-
"version": "0.3.11",
12+
"version": "0.3.12",
1313
"zeroconf": []
1414
}

custom_components/haier_evo/select.py

Lines changed: 13 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,12 @@ async def async_setup_entry(hass: HomeAssistant, config_entry, async_add_entitie
1717

1818

1919
class HaierSelect(SelectEntity):
20+
_attr_should_poll = False
2021
_attr_icon = "mdi:format-list-bulleted"
2122

2223
def __init__(self, device: api.HaierDevice) -> None:
2324
self._device = weakref.proxy(device)
25+
self._device_attr_name = None
2426
self._attr_options = []
2527

2628
device.add_write_ha_state_callback(self.async_write_ha_state)
@@ -33,76 +35,55 @@ def device_info(self) -> dict:
3335
def available(self) -> bool:
3436
return self._device.available
3537

38+
@property
39+
def current_option(self) -> str:
40+
return getattr(self._device, self._device_attr_name, None)
41+
3642
async def async_select_option(self, option: str) -> None:
37-
if option not in self.options:
38-
raise ValueError(f"{option} is not a valid option")
3943
await self.hass.async_add_executor_job(self.set_option, option)
40-
self.async_write_ha_state()
4144

4245
def set_option(self, value) -> None:
43-
pass
46+
method = getattr(self._device, f"set_{self._device_attr_name}", None)
47+
if method is not None:
48+
method(value)
4449

4550

4651
class HaierACEcoSensorSelect(HaierSelect):
4752
_attr_translation_key = "conditioner_eco_sensor"
4853

4954
def __init__(self, device: api.HaierAC) -> None:
5055
super().__init__(device)
56+
self._device_attr_name = "eco_sensor"
5157
self._attr_unique_id = f"{device.device_id}_{device.device_model}_eco_sensor"
5258
self._attr_name = f"{device.device_name} Эко-датчик"
5359
self._attr_options = device.get_eco_sensor_options()
5460

55-
@property
56-
def current_option(self) -> str:
57-
return self._device.eco_sensor
58-
59-
def set_option(self, value) -> None:
60-
self._device.set_eco_sensor(value)
61-
6261

6362
class HaierREFFridgeModeSelect(HaierSelect):
6463

6564
def __init__(self, device: api.HaierREF) -> None:
6665
super().__init__(device)
66+
self._device_attr_name = "fridge_mode"
6767
self._attr_unique_id = f"{device.device_id}_{device.device_model}_fridge_mode_select"
6868
self._attr_name = f"{device.device_name} Режим холодильной камеры"
6969
self._attr_options = device.get_fridge_mode_options()
7070

71-
@property
72-
def current_option(self) -> str:
73-
return self._device.fridge_mode
74-
75-
def set_option(self, value) -> None:
76-
self._device.set_fridge_mode(value)
77-
7871

7972
class HaierREFFreezerModeSelect(HaierSelect):
8073

8174
def __init__(self, device: api.HaierREF) -> None:
8275
super().__init__(device)
76+
self._device_attr_name = "freezer_mode"
8377
self._attr_unique_id = f"{device.device_id}_{device.device_model}_freezer_mode_select"
8478
self._attr_name = f"{device.device_name} Режим морозильной камеры"
8579
self._attr_options = device.get_freezer_mode_options()
8680

87-
@property
88-
def current_option(self) -> str:
89-
return self._device.freezer_mode
90-
91-
def set_option(self, value) -> None:
92-
self._device.set_freezer_mode(value)
93-
9481

9582
class HaierREFMyZoneSelect(HaierSelect):
9683

9784
def __init__(self, device: api.HaierREF) -> None:
9885
super().__init__(device)
86+
self._device_attr_name = "my_zone"
9987
self._attr_unique_id = f"{device.device_id}_{device.device_model}_my_zone"
10088
self._attr_name = f"{device.device_name} My Zone"
10189
self._attr_options = device.get_my_zone_options()
102-
103-
@property
104-
def current_option(self) -> str:
105-
return self._device.my_zone
106-
107-
def set_option(self, value) -> None:
108-
self._device.set_my_zone(value)

custom_components/haier_evo/sensor.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ class HaierSensor(SensorEntity):
2323
def __init__(self, device: api.HaierDevice):
2424
self._device = weakref.proxy(device)
2525
self._device_attr_name = None
26-
self._attr_is_on = False
2726

2827
device.add_write_ha_state_callback(self.async_write_ha_state)
2928

custom_components/haier_evo/switch.py

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,14 @@ async def async_setup_entry(hass: HomeAssistant, config_entry, async_add_entitie
1818

1919

2020
class HaierSwitch(SwitchEntity):
21-
# _attr_should_poll = False
21+
_attr_should_poll = False
2222
_attr_icon = "mdi:toggle-switch"
2323

2424
def __init__(self, device: api.HaierDevice) -> None:
2525
self._device = weakref.proxy(device)
2626
self._device_attr_name = None
27-
self._attr_is_on = False
2827

29-
def write_ha_state_callback():
30-
self.update_state()
31-
self.async_write_ha_state()
32-
device.add_write_ha_state_callback(write_ha_state_callback)
28+
device.add_write_ha_state_callback(self.async_write_ha_state)
3329

3430
@property
3531
def device_info(self) -> dict:
@@ -41,8 +37,6 @@ def available(self) -> bool:
4137

4238
async def async_turn_on(self, **kwargs):
4339
await self.hass.async_add_executor_job(self.turn_on)
44-
self._attr_is_on = True
45-
self.async_write_ha_state()
4640

4741
def turn_on(self) -> None:
4842
method = getattr(self._device, f"set_{self._device_attr_name}", None)
@@ -51,19 +45,15 @@ def turn_on(self) -> None:
5145

5246
async def async_turn_off(self, **kwargs):
5347
await self.hass.async_add_executor_job(self.turn_off)
54-
self._attr_is_on = False
55-
self.async_write_ha_state()
5648

5749
def turn_off(self, **kwargs) -> None:
5850
method = getattr(self._device, f"set_{self._device_attr_name}", None)
5951
if method is not None:
6052
method(False)
6153

62-
def update_state(self) -> None:
63-
self._attr_is_on = bool(getattr(self._device, self._device_attr_name, None))
64-
65-
async def async_update(self):
66-
self.update_state()
54+
@property
55+
def is_on(self) -> bool:
56+
return bool(getattr(self._device, self._device_attr_name, None))
6757

6858

6959
class HaierACLightSwitch(HaierSwitch):

0 commit comments

Comments
 (0)