-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sensor_manifest.py
310 lines (302 loc) · 9.2 KB
/
sensor_manifest.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
from homeassistant import const
from homeassistant.components.binary_sensor import BinarySensorDeviceClass
from homeassistant.components.sensor import SensorEntityDescription, SensorDeviceClass
from .ankermake_mqtt_adapter import AnkerStatus, FilamentType
# Linter is complaining without this class, it is strictly unnecessary
class Description(SensorEntityDescription):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
# Key must match the attribute in the AnkerData class
BINARY_SENSOR_DESCRIPTIONS = [
# Motor Locked
Description(
key="motor_locked",
name="Motor Locked",
icon="mdi:lock",
device_class=BinarySensorDeviceClass.LOCK,
entity_registry_enabled_default=False,
),
]
BINARY_SENSOR_WITH_ATTR_DESCRIPTIONS = [
# AI Enabled
[Description(
key="ai_enabled",
name="AI Detection",
icon="mdi:brain",
device_class=BinarySensorDeviceClass.CONNECTIVITY,
entity_registry_enabled_default=False,
),
{
'state': 'ai_enabled',
'level': 'ai_level',
'pause_print': 'ai_pause_print',
'data_collection': 'ai_data_collection',
}
],
# Filetransfer service
[Description(
key="service_filetransfer",
name="Filetransfer Service",
icon="mdi:console",
device_class=BinarySensorDeviceClass.CONNECTIVITY,
entity_registry_enabled_default=False, # TODO: Enable this when API is in master
),
{
'state': '%SVC_ONLINE=filetransfer',
'status': '%SVC_STATE=filetransfer',
'possible_states': 'api_service_possible_states',
}
],
# PPPPservice
[Description(
key="service_pppp",
name="PPPP Service",
icon="mdi:console",
device_class=BinarySensorDeviceClass.CONNECTIVITY,
entity_registry_enabled_default=False, # TODO: Enable this when API is in master
),
{
'state': '%SVC_ONLINE=pppp',
'status': '%SVC_STATE=pppp',
'possible_states': 'api_service_possible_states',
}
],
# Videoqueue
[Description(
key="service_videoqueue",
name="Videoqueue Service",
icon="mdi:console",
device_class=BinarySensorDeviceClass.CONNECTIVITY,
entity_registry_enabled_default=False, # TODO: Enable this when API is in master
),
{
'state': '%SVC_ONLINE=videoqueue',
'status': '%SVC_STATE=videoqueue',
'possible_states': 'api_service_possible_states',
}
],
# mqtt
[Description(
key="service_mqtt",
name="MQTT Service",
icon="mdi:console",
device_class=BinarySensorDeviceClass.CONNECTIVITY,
entity_registry_enabled_default=False, # TODO: Enable this when API is in master
),
{
'state': '%SVC_ONLINE=mqttqueue',
'status': '%SVC_STATE=mqttqueue',
'possible_states': 'api_service_possible_states',
}
],
]
# Key must match the attribute in the AnkerData class
SENSOR_DESCRIPTIONS = [
# Job Name
Description(
key="job_name",
name="Job Name",
icon="mdi:file-document",
entity_registry_enabled_default=False,
),
# Start Time
Description(
key="print_start_time",
name="Start Time",
icon="mdi:timer-outline",
device_class=SensorDeviceClass.TIMESTAMP,
),
# Target Time
Description(
key="print_target_time",
name="Target Time",
icon="mdi:timer-outline",
device_class=SensorDeviceClass.TIMESTAMP,
),
# Filament Used
Description(
key="filament_used",
name="Filament Used",
icon="mdi:pipe",
native_unit_of_measurement=const.UnitOfLength.METERS,
entity_registry_enabled_default=False,
),
# Filament Weight
Description(
key="filament_weight",
name="Filament Weight",
icon="mdi:weight",
native_unit_of_measurement=const.UnitOfMass.GRAMS,
entity_registry_enabled_default=False,
),
# Filament Density
Description(
key="filament_density",
name="Filament Density",
icon="mdi:weight",
native_unit_of_measurement="m³",
entity_registry_enabled_default=False,
),
# Current Speed
Description(
key="current_speed",
name="Speed",
icon="mdi:speedometer",
native_unit_of_measurement="mm/s",
entity_registry_enabled_default=False,
),
# Max Speed
Description(
key="max_speed",
name="Max Speed",
icon="mdi:speedometer",
native_unit_of_measurement="mm/s",
entity_registry_enabled_default=False,
),
# Fan Speed
Description(
key="fan_speed",
name="Fan Speed",
icon="mdi:fan",
native_unit_of_measurement=const.PERCENTAGE,
entity_registry_enabled_default=False,
),
# Current Layer
Description(
key="current_layer",
name="Layer",
icon="mdi:layers-triple",
entity_registry_enabled_default=False,
),
# Total Layers
Description(
key="total_layers",
name="Total Layers",
icon="mdi:layers-triple",
entity_registry_enabled_default=False,
),
# Target Hotend Temp
Description(
key="target_hotend_temp",
name="Target Hotend Temperature",
icon="mdi:thermometer",
native_unit_of_measurement=const.UnitOfTemperature.CELSIUS,
entity_registry_enabled_default=False,
),
# Target Bed Temp
Description(
key="target_bed_temp",
name="Target Bed Temperature",
icon="mdi:thermometer",
native_unit_of_measurement=const.UnitOfTemperature.CELSIUS,
entity_registry_enabled_default=False,
),
]
# Description Key = entity affix
# Dict = {entity_attribute: key_in_ankerdata} (state sets the entity state)
# If one does not intend to use an ankerdata attribute an if statement must be added to the _update_from_anker method
# in sensor.py to prevent an AttributeError (alternatively see _filter_handler method in sensor.py)
# = denotes a static value ('unit': '=mm/s' would set the unit to mm/s, instead of using an attribute from ankerdata)
SENSOR_WITH_ATTR_DESCRIPTIONS = [
# 3D Printer Sensor
[Description(
key="3d_printer",
name="3D Printer",
icon="mdi:printer-3d",
device_class='enum',
options=[s.value for s in AnkerStatus],
),
{
'state': 'status',
'ai_enabled': 'ai_enabled',
'motor_locked': 'motor_locked',
'error_message': 'error_message',
'error_level': 'error_level',
'config_host': '%CFG=host',
'config_name': '%CFG=printer_name',
'api_version': '%VERSION=api',
'octoprint_version': '%VERSION=server',
}
],
# Hotend Sensor
[Description(
key="hotend",
name="Hotend Temperature",
icon="mdi:thermometer",
native_unit_of_measurement=const.UnitOfTemperature.CELSIUS,
),
{
'state': 'hotend_temp',
'nozzle_type': 'nozzle_type',
'target_temp': 'target_hotend_temp',
'fan_speed': 'fan_speed',
}
],
# Bed Sensor
[Description(
key="bed",
name="Bed Temperature",
icon="mdi:thermometer",
native_unit_of_measurement=const.UnitOfTemperature.CELSIUS,
),
{
'state': 'bed_temp',
'target_temp': 'target_bed_temp',
'bed_leveled': 'bed_leveled',
}
],
# Print job
[Description(
key="progress",
name="Progress",
icon="mdi:file-document",
native_unit_of_measurement=const.PERCENTAGE,
),
{
'state': 'progress',
'gcode_preview_url': 'image',
'job_name': 'job_name',
'elapsed_time': '%%TD=elapsed_time',
'remaining_time': '%%TD=remaining_time',
'total_print_time': '%%TD=total_time',
'start_time': 'print_start_time',
'target_time': 'print_target_time',
'current_speed': 'current_speed',
'max_speed': 'max_speed',
'speed_unit': '=mm/s',
'current_layer': 'current_layer',
'total_layers': 'total_layers',
}
],
# Filament
# TODO: Move from print job to filament sensor
[Description(
key="filament",
name="Filament",
icon="mdi:pipe",
device_class='enum',
options=[s.value for s in FilamentType],
),
{
'state': 'filament',
'filament_used': 'filament_used',
'filament_used_unit': '=m',
'filament_weight': 'filament_weight',
'filament_weight_unit': '=g',
'filament_density': 'filament_density',
'filament_density_unit': '=m³',
}
],
# Error Message
[Description(
key="error",
name="Error",
icon="mdi:alert",
entity_registry_enabled_default=False,
),
{
'state': 'error_message',
'error_level': 'error_level',
}
],
]