Skip to content

Commit 29631a2

Browse files
authored
Cleanup SFR Box sensors (home-assistant#157708)
1 parent 1d31e6d commit 29631a2

File tree

4 files changed

+36
-53
lines changed

4 files changed

+36
-53
lines changed

homeassistant/components/sfr_box/quality_scale.yaml

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,7 @@ rules:
4343

4444
## Gold
4545
entity-translations: done
46-
entity-device-class:
47-
status: todo
48-
comment: |
49-
What does DSL counter count?
50-
What is the state of CRC?
51-
line_status and training and net_infra and mode -> unknown shouldn't be an option and the entity should return None instead
46+
entity-device-class: done
5247
devices:
5348
status: todo
5449
comment: MAC address can be set to the connections

homeassistant/components/sfr_box/sensor.py

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,14 @@ class SFRBoxSensorEntityDescription[_T](SensorEntityDescription):
4949
key="counter",
5050
entity_category=EntityCategory.DIAGNOSTIC,
5151
entity_registry_enabled_default=False,
52-
translation_key="dsl_counter",
52+
translation_key="dsl_connect_count",
5353
value_fn=lambda x: x.counter,
5454
),
5555
SFRBoxSensorEntityDescription[DslInfo](
5656
key="crc",
5757
entity_category=EntityCategory.DIAGNOSTIC,
5858
entity_registry_enabled_default=False,
59-
translation_key="dsl_crc",
59+
translation_key="dsl_crc_error_count",
6060
value_fn=lambda x: x.crc,
6161
),
6262
SFRBoxSensorEntityDescription[DslInfo](
@@ -126,7 +126,6 @@ class SFRBoxSensorEntityDescription[_T](SensorEntityDescription):
126126
"loss_of_signal",
127127
"loss_of_power",
128128
"loss_of_signal_quality",
129-
"unknown",
130129
],
131130
translation_key="dsl_line_status",
132131
value_fn=lambda x: _value_to_option(x.line_status),
@@ -146,7 +145,6 @@ class SFRBoxSensorEntityDescription[_T](SensorEntityDescription):
146145
"g_993_channel_analysis",
147146
"g_993_message_exchange",
148147
"showtime",
149-
"unknown",
150148
],
151149
translation_key="dsl_training",
152150
value_fn=lambda x: _value_to_option(x.training),
@@ -162,10 +160,9 @@ class SFRBoxSensorEntityDescription[_T](SensorEntityDescription):
162160
"adsl",
163161
"ftth",
164162
"gprs",
165-
"unknown",
166163
],
167164
translation_key="net_infra",
168-
value_fn=lambda x: x.net_infra,
165+
value_fn=lambda x: _value_to_option(x.net_infra),
169166
),
170167
SFRBoxSensorEntityDescription[SystemInfo](
171168
key="alimvoltage",
@@ -197,18 +194,17 @@ class SFRBoxSensorEntityDescription[_T](SensorEntityDescription):
197194
"adsl_routed",
198195
"ftth_routed",
199196
"grps_ppp",
200-
"unknown",
201197
],
202198
translation_key="wan_mode",
203-
value_fn=lambda x: x.mode.replace("/", "_"),
199+
value_fn=lambda x: _value_to_option(x.mode),
204200
),
205201
)
206202

207203

208204
def _value_to_option(value: str | None) -> str | None:
209-
if value is None:
210-
return value
211-
return value.lower().replace(" ", "_").replace(".", "_")
205+
if value is None or value == "Unknown":
206+
return None
207+
return value.lower().replace(" ", "_").replace(".", "_").replace("/", "_")
212208

213209

214210
def _get_temperature(value: float | None) -> float | None:

homeassistant/components/sfr_box/strings.json

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,13 @@
5656
"dsl_attenuation_up": {
5757
"name": "DSL attenuation up"
5858
},
59-
"dsl_counter": {
60-
"name": "DSL counter"
59+
"dsl_connect_count": {
60+
"name": "DSL connect count",
61+
"unit_of_measurement": "connects"
6162
},
62-
"dsl_crc": {
63-
"name": "DSL CRC"
63+
"dsl_crc_error_count": {
64+
"name": "DSL CRC error count",
65+
"unit_of_measurement": "errors"
6466
},
6567
"dsl_line_status": {
6668
"name": "DSL line status",
@@ -69,8 +71,7 @@
6971
"loss_of_power": "Loss of power",
7072
"loss_of_signal": "Loss of signal",
7173
"loss_of_signal_quality": "Loss of signal quality",
72-
"no_defect": "No defect",
73-
"unknown": "Unknown"
74+
"no_defect": "No defect"
7475
}
7576
},
7677
"dsl_linemode": {
@@ -99,17 +100,15 @@
99100
"g_993_started": "G.993 Started",
100101
"g_994_training": "G.994 Training",
101102
"idle": "[%key:common::state::idle%]",
102-
"showtime": "Showtime",
103-
"unknown": "Unknown"
103+
"showtime": "Showtime"
104104
}
105105
},
106106
"net_infra": {
107107
"name": "Network infrastructure",
108108
"state": {
109109
"adsl": "ADSL",
110110
"ftth": "FTTH",
111-
"gprs": "GPRS",
112-
"unknown": "Unknown"
111+
"gprs": "GPRS"
113112
}
114113
},
115114
"wan_mode": {
@@ -118,8 +117,7 @@
118117
"adsl_ppp": "ADSL (PPP)",
119118
"adsl_routed": "ADSL (Routed)",
120119
"ftth_routed": "FTTH (Routed)",
121-
"grps_ppp": "GPRS (PPP)",
122-
"unknown": "Unknown"
120+
"grps_ppp": "GPRS (PPP)"
123121
}
124122
}
125123
}

tests/components/sfr_box/snapshots/test_sensor.ambr

Lines changed: 18 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@
105105
'state': '20.8',
106106
})
107107
# ---
108-
# name: test_sensors[sensor.sfr_box_dsl_counter-entry]
108+
# name: test_sensors[sensor.sfr_box_dsl_connect_count-entry]
109109
EntityRegistryEntrySnapshot({
110110
'aliases': set({
111111
}),
@@ -118,7 +118,7 @@
118118
'disabled_by': None,
119119
'domain': 'sensor',
120120
'entity_category': <EntityCategory.DIAGNOSTIC: 'diagnostic'>,
121-
'entity_id': 'sensor.sfr_box_dsl_counter',
121+
'entity_id': 'sensor.sfr_box_dsl_connect_count',
122122
'has_entity_name': True,
123123
'hidden_by': None,
124124
'icon': None,
@@ -130,30 +130,31 @@
130130
}),
131131
'original_device_class': None,
132132
'original_icon': None,
133-
'original_name': 'DSL counter',
133+
'original_name': 'DSL connect count',
134134
'platform': 'sfr_box',
135135
'previous_unique_id': None,
136136
'suggested_object_id': None,
137137
'supported_features': 0,
138-
'translation_key': 'dsl_counter',
138+
'translation_key': 'dsl_connect_count',
139139
'unique_id': 'e4:5d:51:00:11:22_dsl_counter',
140-
'unit_of_measurement': None,
140+
'unit_of_measurement': 'connects',
141141
})
142142
# ---
143-
# name: test_sensors[sensor.sfr_box_dsl_counter-state]
143+
# name: test_sensors[sensor.sfr_box_dsl_connect_count-state]
144144
StateSnapshot({
145145
'attributes': ReadOnlyDict({
146-
'friendly_name': 'SFR Box DSL counter',
146+
'friendly_name': 'SFR Box DSL connect count',
147+
'unit_of_measurement': 'connects',
147148
}),
148149
'context': <ANY>,
149-
'entity_id': 'sensor.sfr_box_dsl_counter',
150+
'entity_id': 'sensor.sfr_box_dsl_connect_count',
150151
'last_changed': <ANY>,
151152
'last_reported': <ANY>,
152153
'last_updated': <ANY>,
153154
'state': '16',
154155
})
155156
# ---
156-
# name: test_sensors[sensor.sfr_box_dsl_crc-entry]
157+
# name: test_sensors[sensor.sfr_box_dsl_crc_error_count-entry]
157158
EntityRegistryEntrySnapshot({
158159
'aliases': set({
159160
}),
@@ -166,7 +167,7 @@
166167
'disabled_by': None,
167168
'domain': 'sensor',
168169
'entity_category': <EntityCategory.DIAGNOSTIC: 'diagnostic'>,
169-
'entity_id': 'sensor.sfr_box_dsl_crc',
170+
'entity_id': 'sensor.sfr_box_dsl_crc_error_count',
170171
'has_entity_name': True,
171172
'hidden_by': None,
172173
'icon': None,
@@ -178,23 +179,24 @@
178179
}),
179180
'original_device_class': None,
180181
'original_icon': None,
181-
'original_name': 'DSL CRC',
182+
'original_name': 'DSL CRC error count',
182183
'platform': 'sfr_box',
183184
'previous_unique_id': None,
184185
'suggested_object_id': None,
185186
'supported_features': 0,
186-
'translation_key': 'dsl_crc',
187+
'translation_key': 'dsl_crc_error_count',
187188
'unique_id': 'e4:5d:51:00:11:22_dsl_crc',
188-
'unit_of_measurement': None,
189+
'unit_of_measurement': 'errors',
189190
})
190191
# ---
191-
# name: test_sensors[sensor.sfr_box_dsl_crc-state]
192+
# name: test_sensors[sensor.sfr_box_dsl_crc_error_count-state]
192193
StateSnapshot({
193194
'attributes': ReadOnlyDict({
194-
'friendly_name': 'SFR Box DSL CRC',
195+
'friendly_name': 'SFR Box DSL CRC error count',
196+
'unit_of_measurement': 'errors',
195197
}),
196198
'context': <ANY>,
197-
'entity_id': 'sensor.sfr_box_dsl_crc',
199+
'entity_id': 'sensor.sfr_box_dsl_crc_error_count',
198200
'last_changed': <ANY>,
199201
'last_reported': <ANY>,
200202
'last_updated': <ANY>,
@@ -261,7 +263,6 @@
261263
'loss_of_signal',
262264
'loss_of_power',
263265
'loss_of_signal_quality',
264-
'unknown',
265266
]),
266267
}),
267268
'config_entry_id': <ANY>,
@@ -304,7 +305,6 @@
304305
'loss_of_signal',
305306
'loss_of_power',
306307
'loss_of_signal_quality',
307-
'unknown',
308308
]),
309309
}),
310310
'context': <ANY>,
@@ -549,7 +549,6 @@
549549
'g_993_channel_analysis',
550550
'g_993_message_exchange',
551551
'showtime',
552-
'unknown',
553552
]),
554553
}),
555554
'config_entry_id': <ANY>,
@@ -596,7 +595,6 @@
596595
'g_993_channel_analysis',
597596
'g_993_message_exchange',
598597
'showtime',
599-
'unknown',
600598
]),
601599
}),
602600
'context': <ANY>,
@@ -617,7 +615,6 @@
617615
'adsl',
618616
'ftth',
619617
'gprs',
620-
'unknown',
621618
]),
622619
}),
623620
'config_entry_id': <ANY>,
@@ -658,7 +655,6 @@
658655
'adsl',
659656
'ftth',
660657
'gprs',
661-
'unknown',
662658
]),
663659
}),
664660
'context': <ANY>,
@@ -792,7 +788,6 @@
792788
'adsl_routed',
793789
'ftth_routed',
794790
'grps_ppp',
795-
'unknown',
796791
]),
797792
}),
798793
'config_entry_id': <ANY>,
@@ -834,7 +829,6 @@
834829
'adsl_routed',
835830
'ftth_routed',
836831
'grps_ppp',
837-
'unknown',
838832
]),
839833
}),
840834
'context': <ANY>,

0 commit comments

Comments
 (0)