|
37 | 37 | from munch import Munch |
38 | 38 |
|
39 | 39 |
|
| 40 | +def model_to_switch_items(model: str, state: str, switch: Munch) -> tuple[str, Munch]: |
| 41 | + """Translate state and switch attributes based on model name. |
| 42 | +
|
| 43 | + Helper function for set_switch_state(). |
| 44 | + """ |
| 45 | + match model: |
| 46 | + case "dhw_cm_switch": |
| 47 | + switch.device = "toggle" |
| 48 | + switch.func_type = "toggle_functionality" |
| 49 | + switch.act_type = "domestic_hot_water_comfort_mode" |
| 50 | + case "cooling_ena_switch": |
| 51 | + switch.device = "toggle" |
| 52 | + switch.func_type = "toggle_functionality" |
| 53 | + switch.act_type = "cooling_enabled" |
| 54 | + case "lock": |
| 55 | + switch.func = "lock" |
| 56 | + state = "true" if state == STATE_ON else "false" |
| 57 | + |
| 58 | + return state, switch |
| 59 | + |
| 60 | + |
40 | 61 | class SmileAPI(SmileData): |
41 | 62 | """The Plugwise SmileAPI helper class for actual Plugwise devices.""" |
42 | 63 |
|
@@ -381,20 +402,7 @@ async def set_switch_state( |
381 | 402 | switch.device = "relay" |
382 | 403 | switch.func_type = "relay_functionality" |
383 | 404 | switch.func = "state" |
384 | | - if model == "dhw_cm_switch": |
385 | | - switch.device = "toggle" |
386 | | - switch.func_type = "toggle_functionality" |
387 | | - switch.act_type = "domestic_hot_water_comfort_mode" |
388 | | - |
389 | | - if model == "cooling_ena_switch": |
390 | | - switch.device = "toggle" |
391 | | - switch.func_type = "toggle_functionality" |
392 | | - switch.act_type = "cooling_enabled" |
393 | | - |
394 | | - if model == "lock": |
395 | | - switch.func = "lock" |
396 | | - state = "true" if state == STATE_ON else "false" |
397 | | - |
| 405 | + state, switch = model_to_switch_items(model, state, switch) |
398 | 406 | data = ( |
399 | 407 | f"<{switch.func_type}>" |
400 | 408 | f"<{switch.func}>{state}</{switch.func}>" |
|
0 commit comments