-
Notifications
You must be signed in to change notification settings - Fork 7
/
documentation.py
201 lines (184 loc) · 7.43 KB
/
documentation.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
"""Write documentation."""
from tesla_fleet_api.const import TelemetryField
from itertools import chain
import json
from custom_components.teslemetry.binary_sensor import (
VEHICLE_DESCRIPTIONS as BINARY_VEHICLE_DESCRIPTIONS,
VEHICLE_STREAM_DESCRIPTIONS as BINARY_VEHICLE_STREAM_DESCRIPTIONS,
ENERGY_LIVE_DESCRIPTIONS as BINARY_ENERGY_LIVE_DESCRIPTIONS,
ENERGY_INFO_DESCRIPTIONS as BINARY_ENERGY_INFO_DESCRIPTIONS,
)
from custom_components.teslemetry.button import DESCRIPTIONS as BUTTON_DESCRIPTIONS
from custom_components.teslemetry.number import (
VEHICLE_DESCRIPTIONS as NUMBER_VEHICLE_DESCRIPTIONS,
ENERGY_INFO_DESCRIPTIONS as NUMBER_ENERGY_INFO_DESCRIPTIONS,
)
from custom_components.teslemetry.select import (
SEAT_HEATER_DESCRIPTIONS as SELECT_SEAT_HEATER_DESCRIPTIONS,
)
from custom_components.teslemetry.sensor import (
VEHICLE_DESCRIPTIONS as SENSOR_VEHICLE_DESCRIPTIONS,
VEHICLE_STREAM_DESCRIPTIONS as SENSOR_VEHICLE_STREAM_DESCRIPTIONS,
VEHICLE_TIME_DESCRIPTIONS as SENSOR_VEHICLE_TIME_DESCRIPTIONS,
ENERGY_INFO_DESCRIPTIONS as SENSOR_ENERGY_INFO_DESCRIPTIONS,
ENERGY_LIVE_DESCRIPTIONS as SENSOR_ENERGY_LIVE_DESCRIPTIONS,
WALL_CONNECTOR_DESCRIPTIONS as SENSOR_WALL_CONNECTOR_DESCRIPTIONS,
)
from custom_components.teslemetry.switch import (
VEHICLE_DESCRIPTIONS as SWITCH_VEHICLE_DESCRIPTIONS,
)
# Load strings.json
strings = json.load(open("custom_components/teslemetry/strings.json"))
en = json.load(open("custom_components/teslemetry/translations/en.json"))
# Recursively compare keys from strings.json and en.json
def compare_keys(a, b, parent=""):
for key, value in a.items():
if key not in b:
print(f"{parent}{key} not found")
elif isinstance(value, dict):
compare_keys(value, b[key], f"{parent}{key}.")
# compare_keys(strings, en, "strings.json ")
# compare_keys(en, strings, "en.json ")
used = []
streaming_used = []
domains = ("binary_sensor", "button", "number", "select", "sensor", "switch")
domain_names = {
'binary_sensor': "Binary sensor",
'device_tracker': "Device tracker",
'button': "Button",
'cover': "Cover",
'climate': "Climate",
'number': "Number",
'media_player': "Media player",
'lock': "Lock",
'select': "Select",
'sensor': "Sensor",
'switch': "Switch",
'update': "Update"
}
# Iterate over all entities
output = []
for domain, type, descriptions in (
(
"binary_sensor",
"Vehicle",
chain(
BINARY_VEHICLE_DESCRIPTIONS,
BINARY_VEHICLE_STREAM_DESCRIPTIONS,
),
),
(
"binary_sensor",
"Energy Site",
chain(
BINARY_ENERGY_LIVE_DESCRIPTIONS,
BINARY_ENERGY_INFO_DESCRIPTIONS,
),
),
("button", "Vehicle", BUTTON_DESCRIPTIONS),
("number", "Vehicle", NUMBER_VEHICLE_DESCRIPTIONS),
("number", "Energy Site", NUMBER_ENERGY_INFO_DESCRIPTIONS),
("select", "Vehicle", SELECT_SEAT_HEATER_DESCRIPTIONS),
(
"sensor",
"Vehicle",
chain(
SENSOR_VEHICLE_DESCRIPTIONS,
SENSOR_VEHICLE_TIME_DESCRIPTIONS,
SENSOR_VEHICLE_STREAM_DESCRIPTIONS,
)
),(
"sensor",
"Energy Site",
chain(
SENSOR_ENERGY_INFO_DESCRIPTIONS,
SENSOR_ENERGY_LIVE_DESCRIPTIONS
),
),(
"sensor",
"Wall Connector",
SENSOR_WALL_CONNECTOR_DESCRIPTIONS,
),
("switch", "Vehicle", SWITCH_VEHICLE_DESCRIPTIONS),
):
for description in descriptions:
if isinstance(description.key, TelemetryField):
key = f"{description.key.value}"
translation_key = f"stream_{description.key.value.lower()}"
else:
key = description.key
translation_key = description.key
#if key not in strings["entity"][domain]:
# print(f"No string for {domain} {key}")
if translation_key not in en["entity"][domain]:
print(f"ISSUE: No en for {domain} {translation_key}")
else:
used.append((domain, translation_key))
method = "Polling"
if (
hasattr(description, "streaming_key")
and description.streaming_key is not None
):
method = "Both"
elif isinstance(description.key, TelemetryField):
method = "Streaming"
enabled = "Yes"
if description.entity_registry_enabled_default == False:
enabled = "No"
output.append(
f"|{type}|{domain_names[domain]}|{en['entity'][domain][translation_key]['name']}|{method}|{enabled}|"
)
extras = [
("Vehicle","button","refresh","Polling","Yes"),
("Energy site","select","default_real_mode","Polling","Yes"),
("Energy site","select","components_customer_preferred_export_rule","Polling","Yes"),
("Vehicle","sensor","charge_state_minutes_to_full_charge_timestamp","Polling","Yes"),
("Vehicle","sensor","drive_state_active_route_minutes_to_arrival_timestamp","Polling","Yes"),
("Vehicle","switch","charge_state_user_charge_enable_request","Polling","Yes"),
("Vehicle","select","climate_state_steering_wheel_heat_level","Polling","Yes"),
("Energy site","switch","user_settings_storm_mode_enabled","Polling","Yes"),
("Energy site","switch","components_disallow_charge_from_grid_with_solar_installed","Polling","Yes"),
("Wall connector","sensor","vin","Polling","Yes"),
("Vehicle","climate","driver_temp","Polling^1","Yes"),
("Vehicle","climate","climate_state_cabin_overheat_protection","Both^1","Yes"),
("Vehicle","cover","windows","Polling","Yes"),
("Vehicle","cover","charge_state_charge_port_door_open","Both","Yes"),
("Vehicle","cover","vehicle_state_ft","Polling","Yes"),
("Vehicle","cover","vehicle_state_rt","Polling","Yes"),
("Vehicle","device_tracker","location","Both","Yes"),
("Vehicle","device_tracker","route","Polling","Yes"),
("Vehicle","lock","vehicle_state_locked","Both","Yes"),
("Vehicle","lock","charge_state_charge_port_latch","Both","Yes"),
("Vehicle","lock","vehicle_state_speed_limit_mode_active","Both","Yes"),
("Vehicle","media_player","media","Polling","Yes"),
("Vehicle","update","vehicle_state_software_update_status","Both^2","Yes"),
]
for type, domain, key, method, enabled in extras:
output.append(
f"|{type}|{domain_names[domain]}|{en['entity'][domain][key]['name']}|{method}|{enabled}|"
)
output.sort()
# write output to file
with open("documentation.md", "w") as f:
f.write("|Device|Domain|Name|Method|Enabled|\n")
f.write("|---|---|---|---|---|\n")
f.write("\n".join(output))
f.write("\n\n^1 Only inside temperature is streamable\n^2 Only version is streamable\n")
# Check for unused
for domain in en["entity"]:
if domain in domains:
for key in en["entity"][domain]:
if key not in (
"refresh",
"default_real_mode",
"components_customer_preferred_export_rule",
"charge_state_minutes_to_full_charge_timestamp",
"drive_state_active_route_minutes_to_arrival_timestamp",
"charge_state_user_charge_enable_request",
"climate_state_steering_wheel_heat_level",
"user_settings_storm_mode_enabled",
"components_disallow_charge_from_grid_with_solar_installed",
"vin",
):
if (domain, key) not in used:
print(f"UNUSED: {domain} {key}")