45
45
# general ac attributes
46
46
ATTR_FRIDGE = "fridge"
47
47
ATTR_FREEZER = "freezer"
48
- ATTR_SWING_HORIZONTAL = "swing_mode_horizontal"
49
- ATTR_SWING_VERTICAL = "swing_mode_vertical"
50
48
HVAC_MODE_NONE = "--"
51
- SWING_PREFIX = ["Vertical" , "Horizontal" ]
52
49
53
50
# service definitions
54
51
SERVICE_SET_SLEEP_TIME = "set_sleep_time"
@@ -211,16 +208,21 @@ def __init__(self, api: LGEDevice) -> None:
211
208
self ._attr_fan_modes = [
212
209
FAN_MODE_LOOKUP .get (s , s ) for s in self ._device .fan_speeds
213
210
]
214
- self ._attr_swing_modes = [
215
- f"{ SWING_PREFIX [0 ]} { mode } " for mode in self ._device .vertical_step_modes
216
- ] + [f"{ SWING_PREFIX [1 ]} { mode } " for mode in self ._device .horizontal_step_modes ]
211
+
212
+ self ._use_h_mode = False
213
+ self ._attr_swing_modes = self ._device .vertical_step_modes or None
214
+ if not self ._attr_swing_modes :
215
+ self ._attr_swing_modes = self ._device .horizontal_step_modes or None
216
+ self ._use_h_mode = self ._attr_swing_modes is not None
217
+ else :
218
+ self ._attr_swing_horizontal_modes = (
219
+ self ._device .horizontal_step_modes or None
220
+ )
221
+
217
222
self ._attr_preset_mode = None
218
223
219
224
self ._hvac_mode_lookup : dict [str , HVACMode ] | None = None
220
225
self ._preset_mode_lookup : dict [str , str ] | None = None
221
- self ._support_ver_swing = len (self ._device .vertical_step_modes ) > 0
222
- self ._support_hor_swing = len (self ._device .horizontal_step_modes ) > 0
223
- self ._set_hor_swing = self ._support_hor_swing and not self ._support_ver_swing
224
226
225
227
def _available_hvac_modes (self ) -> dict [str , HVACMode ]:
226
228
"""Return available hvac modes from lookup dict."""
@@ -253,16 +255,6 @@ def _available_preset_modes(self) -> dict[str, str]:
253
255
self ._preset_mode_lookup = {v : k for k , v in modes .items ()}
254
256
return self ._preset_mode_lookup
255
257
256
- def _get_swing_mode (self , hor_mode = False ) -> str | None :
257
- """Return the current swing mode for vert of hor mode."""
258
- if hor_mode :
259
- mode = self ._api .state .horizontal_step_mode
260
- else :
261
- mode = self ._api .state .vertical_step_mode
262
- if mode :
263
- return f"{ SWING_PREFIX [1 if hor_mode else 0 ]} { mode } "
264
- return None
265
-
266
258
@property
267
259
def supported_features (self ) -> ClimateEntityFeature :
268
260
"""Return the list of supported features."""
@@ -271,21 +263,12 @@ def supported_features(self) -> ClimateEntityFeature:
271
263
features |= ClimateEntityFeature .FAN_MODE
272
264
if self .preset_modes :
273
265
features |= ClimateEntityFeature .PRESET_MODE
274
- if self ._support_ver_swing or self . _support_hor_swing :
266
+ if self .swing_modes :
275
267
features |= ClimateEntityFeature .SWING_MODE
268
+ if self .swing_horizontal_modes :
269
+ features |= ClimateEntityFeature .SWING_HORIZONTAL_MODE
276
270
return features
277
271
278
- @property
279
- def extra_state_attributes (self ):
280
- """Return the optional state attributes with device specific additions."""
281
- attr = {}
282
- if self ._support_hor_swing :
283
- attr [ATTR_SWING_HORIZONTAL ] = self ._get_swing_mode (True )
284
- if self ._support_ver_swing :
285
- attr [ATTR_SWING_VERTICAL ] = self ._get_swing_mode (False )
286
-
287
- return attr
288
-
289
272
@property
290
273
def target_temperature_step (self ) -> float :
291
274
"""Return the supported step of target temperature."""
@@ -410,35 +393,37 @@ async def async_set_fan_mode(self, fan_mode: str) -> None:
410
393
@property
411
394
def swing_mode (self ) -> str | None :
412
395
"""Return the swing mode setting."""
413
- if self ._set_hor_swing and self . _support_hor_swing :
414
- return self ._get_swing_mode ( True )
415
- return self ._get_swing_mode ( False )
396
+ if self ._use_h_mode :
397
+ return self ._api . state . horizontal_step_mode
398
+ return self ._api . state . vertical_step_mode
416
399
417
400
async def async_set_swing_mode (self , swing_mode : str ) -> None :
418
- """Set new target swing mode."""
419
- avl_mode = False
420
- curr_mode = None
421
- set_hor_swing = swing_mode .startswith (SWING_PREFIX [1 ])
422
- dev_mode = remove_prefix (swing_mode , SWING_PREFIX [1 if set_hor_swing else 0 ])
423
- if set_hor_swing :
424
- if dev_mode in self ._device .horizontal_step_modes :
425
- avl_mode = True
426
- curr_mode = self ._api .state .horizontal_step_mode
427
- elif swing_mode .startswith (SWING_PREFIX [0 ]):
428
- if dev_mode in self ._device .vertical_step_modes :
429
- avl_mode = True
430
- curr_mode = self ._api .state .vertical_step_mode
431
-
432
- if not avl_mode :
401
+ """Set new target swing operation."""
402
+ if swing_mode not in (self .swing_modes or []):
433
403
raise ValueError (f"Invalid swing_mode [{ swing_mode } ]." )
434
404
435
- if curr_mode != dev_mode :
436
- if set_hor_swing :
437
- await self ._device .set_horizontal_step_mode (dev_mode )
405
+ if swing_mode != self . swing_mode :
406
+ if self . _use_h_mode :
407
+ await self ._device .set_horizontal_step_mode (swing_mode )
438
408
else :
439
- await self ._device .set_vertical_step_mode (dev_mode )
409
+ await self ._device .set_vertical_step_mode (swing_mode )
410
+ self ._api .async_set_updated ()
411
+
412
+ @property
413
+ def swing_horizontal_mode (self ) -> str | None :
414
+ """Return the horizontal swing mode setting."""
415
+ return self ._api .state .horizontal_step_mode
416
+
417
+ async def async_set_swing_horizontal_mode (self , swing_horizontal_mode : str ) -> None :
418
+ """Set new target horizontal swing operation."""
419
+ if swing_horizontal_mode not in (self .swing_horizontal_modes or []):
420
+ raise ValueError (
421
+ f"Invalid horizontal swing_mode [{ swing_horizontal_mode } ]."
422
+ )
423
+
424
+ if swing_horizontal_mode != self .swing_horizontal_mode :
425
+ await self ._device .set_horizontal_step_mode (swing_horizontal_mode )
440
426
self ._api .async_set_updated ()
441
- self ._set_hor_swing = set_hor_swing
442
427
443
428
async def async_turn_on (self ) -> None :
444
429
"""Turn the entity on."""
0 commit comments