Home Assistant Unofficial Reference 2024.12.1
helpers.py
Go to the documentation of this file.
1 """Helper collection for myuplink."""
2 
3 from myuplink import DevicePoint
4 
5 from homeassistant.components.number import NumberEntityDescription
6 from homeassistant.components.sensor import SensorEntityDescription
7 from homeassistant.const import Platform
8 
9 from .const import F_SERIES
10 
11 
13  device_point: DevicePoint,
14  description: SensorEntityDescription | NumberEntityDescription | None = None,
15 ) -> Platform:
16  """Find entity platform for a DevicePoint."""
17  if (
18  len(device_point.enum_values) == 2
19  and device_point.enum_values[0]["value"] == "0"
20  and device_point.enum_values[1]["value"] == "1"
21  ):
22  if device_point.writable:
23  return Platform.SWITCH
24  return Platform.BINARY_SENSOR
25 
26  if len(device_point.enum_values) > 0 and device_point.writable:
27  return Platform.SELECT
28 
29  if (
30  description
31  and description.native_unit_of_measurement == "DM"
32  or (device_point.raw["maxValue"] and device_point.raw["minValue"])
33  ):
34  if device_point.writable:
35  return Platform.NUMBER
36  return Platform.SENSOR
37 
38  return Platform.SENSOR
39 
40 
41 WEEKDAYS = (
42  "monday",
43  "tuesday",
44  "wednesday",
45  "thursday",
46  "friday",
47  "saturday",
48  "sunday",
49 )
50 
51 PARAMETER_ID_TO_EXCLUDE_F730 = (
52  "40940",
53  "47007",
54  "47015",
55  "47020",
56  "47021",
57  "47022",
58  "47023",
59  "47024",
60  "47025",
61  "47026",
62  "47027",
63  "47028",
64  "47032",
65  "47050",
66  "47051",
67  "47206",
68  "47209",
69  "47271",
70  "47272",
71  "47273",
72  "47274",
73  "47375",
74  "47376",
75  "47538",
76  "47539",
77  "47635",
78  "47669",
79  "47703",
80  "47737",
81  "47771",
82  "47772",
83  "47805",
84  "47806",
85  "47839",
86  "47840",
87  "47907",
88  "47941",
89  "47975",
90  "48009",
91  "48072",
92  "48442",
93  "49909",
94  "50113",
95 )
96 
97 PARAMETER_ID_TO_INCLUDE_SMO20 = (
98  "40940",
99  "47011",
100  "47015",
101  "47028",
102  "47032",
103  "50004",
104 )
105 
106 
107 def skip_entity(model: str, device_point: DevicePoint) -> bool:
108  """Check if entity should be skipped for this device model."""
109  if model == "SMO 20":
110  if (
111  len(device_point.smart_home_categories) > 0
112  or device_point.parameter_id in PARAMETER_ID_TO_INCLUDE_SMO20
113  ):
114  return False
115  return True
116  if model.lower().startswith("f"):
117  # Entity names containing weekdays are used for advanced scheduling in the
118  # heat pump and should not be exposed in the integration
119  if any(d in device_point.parameter_name.lower() for d in WEEKDAYS):
120  return True
121  if device_point.parameter_id in PARAMETER_ID_TO_EXCLUDE_F730:
122  return True
123  return False
124 
125 
126 def transform_model_series(prefix: str) -> str:
127  """Remap all F-series models."""
128  if prefix.lower().startswith("f"):
129  return F_SERIES
130  return prefix