Use entity name translations in SFR Box (#90698)
This commit is contained in:
parent
628142527d
commit
45038bac16
8 changed files with 104 additions and 55 deletions
|
@ -42,28 +42,28 @@ class SFRBoxBinarySensorEntityDescription(
|
|||
DSL_SENSOR_TYPES: tuple[SFRBoxBinarySensorEntityDescription[DslInfo], ...] = (
|
||||
SFRBoxBinarySensorEntityDescription[DslInfo](
|
||||
key="status",
|
||||
name="DSL status",
|
||||
device_class=BinarySensorDeviceClass.CONNECTIVITY,
|
||||
entity_category=EntityCategory.DIAGNOSTIC,
|
||||
value_fn=lambda x: x.status == "up",
|
||||
translation_key="dsl_status",
|
||||
),
|
||||
)
|
||||
FTTH_SENSOR_TYPES: tuple[SFRBoxBinarySensorEntityDescription[FtthInfo], ...] = (
|
||||
SFRBoxBinarySensorEntityDescription[FtthInfo](
|
||||
key="status",
|
||||
name="FTTH status",
|
||||
device_class=BinarySensorDeviceClass.CONNECTIVITY,
|
||||
entity_category=EntityCategory.DIAGNOSTIC,
|
||||
value_fn=lambda x: x.status == "up",
|
||||
translation_key="ftth_status",
|
||||
),
|
||||
)
|
||||
WAN_SENSOR_TYPES: tuple[SFRBoxBinarySensorEntityDescription[WanInfo], ...] = (
|
||||
SFRBoxBinarySensorEntityDescription[WanInfo](
|
||||
key="status",
|
||||
name="WAN status",
|
||||
device_class=BinarySensorDeviceClass.CONNECTIVITY,
|
||||
entity_category=EntityCategory.DIAGNOSTIC,
|
||||
value_fn=lambda x: x.status == "up",
|
||||
translation_key="wan_status",
|
||||
),
|
||||
)
|
||||
|
||||
|
|
|
@ -66,7 +66,7 @@ BUTTON_TYPES: tuple[SFRBoxButtonEntityDescription, ...] = (
|
|||
device_class=ButtonDeviceClass.RESTART,
|
||||
entity_category=EntityCategory.CONFIG,
|
||||
key="system_reboot",
|
||||
name="Reboot",
|
||||
translation_key="reboot",
|
||||
),
|
||||
)
|
||||
|
||||
|
|
|
@ -46,84 +46,83 @@ class SFRBoxSensorEntityDescription(SensorEntityDescription, SFRBoxSensorMixin[_
|
|||
DSL_SENSOR_TYPES: tuple[SFRBoxSensorEntityDescription[DslInfo], ...] = (
|
||||
SFRBoxSensorEntityDescription[DslInfo](
|
||||
key="linemode",
|
||||
name="DSL line mode",
|
||||
entity_category=EntityCategory.DIAGNOSTIC,
|
||||
entity_registry_enabled_default=False,
|
||||
translation_key="dsl_linemode",
|
||||
value_fn=lambda x: x.linemode,
|
||||
),
|
||||
SFRBoxSensorEntityDescription[DslInfo](
|
||||
key="counter",
|
||||
name="DSL counter",
|
||||
entity_category=EntityCategory.DIAGNOSTIC,
|
||||
entity_registry_enabled_default=False,
|
||||
translation_key="dsl_counter",
|
||||
value_fn=lambda x: x.counter,
|
||||
),
|
||||
SFRBoxSensorEntityDescription[DslInfo](
|
||||
key="crc",
|
||||
name="DSL CRC",
|
||||
entity_category=EntityCategory.DIAGNOSTIC,
|
||||
entity_registry_enabled_default=False,
|
||||
translation_key="dsl_crc",
|
||||
value_fn=lambda x: x.crc,
|
||||
),
|
||||
SFRBoxSensorEntityDescription[DslInfo](
|
||||
key="noise_down",
|
||||
name="DSL noise down",
|
||||
device_class=SensorDeviceClass.SIGNAL_STRENGTH,
|
||||
entity_category=EntityCategory.DIAGNOSTIC,
|
||||
entity_registry_enabled_default=False,
|
||||
native_unit_of_measurement=SIGNAL_STRENGTH_DECIBELS,
|
||||
state_class=SensorStateClass.MEASUREMENT,
|
||||
translation_key="dsl_noise_down",
|
||||
value_fn=lambda x: x.noise_down,
|
||||
),
|
||||
SFRBoxSensorEntityDescription[DslInfo](
|
||||
key="noise_up",
|
||||
name="DSL noise up",
|
||||
device_class=SensorDeviceClass.SIGNAL_STRENGTH,
|
||||
entity_category=EntityCategory.DIAGNOSTIC,
|
||||
entity_registry_enabled_default=False,
|
||||
native_unit_of_measurement=SIGNAL_STRENGTH_DECIBELS,
|
||||
state_class=SensorStateClass.MEASUREMENT,
|
||||
translation_key="dsl_noise_up",
|
||||
value_fn=lambda x: x.noise_up,
|
||||
),
|
||||
SFRBoxSensorEntityDescription[DslInfo](
|
||||
key="attenuation_down",
|
||||
name="DSL attenuation down",
|
||||
device_class=SensorDeviceClass.SIGNAL_STRENGTH,
|
||||
entity_category=EntityCategory.DIAGNOSTIC,
|
||||
entity_registry_enabled_default=False,
|
||||
native_unit_of_measurement=SIGNAL_STRENGTH_DECIBELS,
|
||||
state_class=SensorStateClass.MEASUREMENT,
|
||||
translation_key="dsl_attenuation_down",
|
||||
value_fn=lambda x: x.attenuation_down,
|
||||
),
|
||||
SFRBoxSensorEntityDescription[DslInfo](
|
||||
key="attenuation_up",
|
||||
name="DSL attenuation up",
|
||||
device_class=SensorDeviceClass.SIGNAL_STRENGTH,
|
||||
entity_category=EntityCategory.DIAGNOSTIC,
|
||||
entity_registry_enabled_default=False,
|
||||
native_unit_of_measurement=SIGNAL_STRENGTH_DECIBELS,
|
||||
state_class=SensorStateClass.MEASUREMENT,
|
||||
translation_key="dsl_attenuation_up",
|
||||
value_fn=lambda x: x.attenuation_up,
|
||||
),
|
||||
SFRBoxSensorEntityDescription[DslInfo](
|
||||
key="rate_down",
|
||||
name="DSL rate down",
|
||||
device_class=SensorDeviceClass.DATA_RATE,
|
||||
native_unit_of_measurement=UnitOfDataRate.KILOBITS_PER_SECOND,
|
||||
state_class=SensorStateClass.MEASUREMENT,
|
||||
translation_key="dsl_rate_down",
|
||||
value_fn=lambda x: x.rate_down,
|
||||
),
|
||||
SFRBoxSensorEntityDescription[DslInfo](
|
||||
key="rate_up",
|
||||
name="DSL rate up",
|
||||
device_class=SensorDeviceClass.DATA_RATE,
|
||||
native_unit_of_measurement=UnitOfDataRate.KILOBITS_PER_SECOND,
|
||||
state_class=SensorStateClass.MEASUREMENT,
|
||||
translation_key="dsl_rate_up",
|
||||
value_fn=lambda x: x.rate_up,
|
||||
),
|
||||
SFRBoxSensorEntityDescription[DslInfo](
|
||||
key="line_status",
|
||||
name="DSL line status",
|
||||
device_class=SensorDeviceClass.ENUM,
|
||||
entity_category=EntityCategory.DIAGNOSTIC,
|
||||
entity_registry_enabled_default=False,
|
||||
|
@ -135,12 +134,11 @@ DSL_SENSOR_TYPES: tuple[SFRBoxSensorEntityDescription[DslInfo], ...] = (
|
|||
"loss_of_signal_quality",
|
||||
"unknown",
|
||||
],
|
||||
translation_key="line_status",
|
||||
translation_key="dsl_line_status",
|
||||
value_fn=lambda x: x.line_status.lower().replace(" ", "_"),
|
||||
),
|
||||
SFRBoxSensorEntityDescription[DslInfo](
|
||||
key="training",
|
||||
name="DSL training",
|
||||
device_class=SensorDeviceClass.ENUM,
|
||||
entity_category=EntityCategory.DIAGNOSTIC,
|
||||
entity_registry_enabled_default=False,
|
||||
|
@ -156,14 +154,13 @@ DSL_SENSOR_TYPES: tuple[SFRBoxSensorEntityDescription[DslInfo], ...] = (
|
|||
"showtime",
|
||||
"unknown",
|
||||
],
|
||||
translation_key="training",
|
||||
translation_key="dsl_training",
|
||||
value_fn=lambda x: x.training.lower().replace(" ", "_").replace(".", "_"),
|
||||
),
|
||||
)
|
||||
SYSTEM_SENSOR_TYPES: tuple[SFRBoxSensorEntityDescription[SystemInfo], ...] = (
|
||||
SFRBoxSensorEntityDescription[SystemInfo](
|
||||
key="net_infra",
|
||||
name="Network infrastructure",
|
||||
device_class=SensorDeviceClass.ENUM,
|
||||
entity_category=EntityCategory.DIAGNOSTIC,
|
||||
entity_registry_enabled_default=False,
|
||||
|
@ -178,27 +175,26 @@ SYSTEM_SENSOR_TYPES: tuple[SFRBoxSensorEntityDescription[SystemInfo], ...] = (
|
|||
),
|
||||
SFRBoxSensorEntityDescription[SystemInfo](
|
||||
key="alimvoltage",
|
||||
name="Voltage",
|
||||
device_class=SensorDeviceClass.VOLTAGE,
|
||||
entity_category=EntityCategory.DIAGNOSTIC,
|
||||
entity_registry_enabled_default=False,
|
||||
native_unit_of_measurement=UnitOfElectricPotential.MILLIVOLT,
|
||||
translation_key="voltage",
|
||||
value_fn=lambda x: x.alimvoltage,
|
||||
),
|
||||
SFRBoxSensorEntityDescription[SystemInfo](
|
||||
key="temperature",
|
||||
name="Temperature",
|
||||
device_class=SensorDeviceClass.TEMPERATURE,
|
||||
entity_category=EntityCategory.DIAGNOSTIC,
|
||||
entity_registry_enabled_default=False,
|
||||
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
|
||||
translation_key="temperature",
|
||||
value_fn=lambda x: x.temperature / 1000,
|
||||
),
|
||||
)
|
||||
WAN_SENSOR_TYPES: tuple[SFRBoxSensorEntityDescription[WanInfo], ...] = (
|
||||
SFRBoxSensorEntityDescription[WanInfo](
|
||||
key="mode",
|
||||
name="WAN mode",
|
||||
device_class=SensorDeviceClass.ENUM,
|
||||
entity_category=EntityCategory.DIAGNOSTIC,
|
||||
entity_registry_enabled_default=False,
|
||||
|
|
|
@ -31,8 +31,40 @@
|
|||
}
|
||||
},
|
||||
"entity": {
|
||||
"binary_sensor": {
|
||||
"dsl_status": {
|
||||
"name": "DSL status"
|
||||
},
|
||||
"ftth_status": {
|
||||
"name": "FTTH status"
|
||||
},
|
||||
"wan_status": {
|
||||
"name": "WAN status"
|
||||
}
|
||||
},
|
||||
"button": {
|
||||
"reboot": {
|
||||
"name": "[%key:component::button::entity_component::restart::name%]"
|
||||
}
|
||||
},
|
||||
"sensor": {
|
||||
"line_status": {
|
||||
"dsl_attenuation_down": {
|
||||
"name": "DSL attenuation down"
|
||||
},
|
||||
"dsl_attenuation_up": {
|
||||
"name": "DSL attenuation up"
|
||||
},
|
||||
"dsl_crc": {
|
||||
"name": "DSL CRC"
|
||||
},
|
||||
"dsl_counter": {
|
||||
"name": "DSL counter"
|
||||
},
|
||||
"dsl_linemode": {
|
||||
"name": "DSL line mode"
|
||||
},
|
||||
"dsl_line_status": {
|
||||
"name": "DSL line status",
|
||||
"state": {
|
||||
"no_defect": "No Defect",
|
||||
"of_frame": "Of Frame",
|
||||
|
@ -42,15 +74,20 @@
|
|||
"unknown": "Unknown"
|
||||
}
|
||||
},
|
||||
"net_infra": {
|
||||
"state": {
|
||||
"adsl": "ADSL",
|
||||
"ftth": "FTTH",
|
||||
"gprs": "GPRS",
|
||||
"unknown": "Unknown"
|
||||
}
|
||||
"dsl_noise_down": {
|
||||
"name": "DSL noise down"
|
||||
},
|
||||
"training": {
|
||||
"dsl_noise_up": {
|
||||
"name": "DSL noise up"
|
||||
},
|
||||
"dsl_rate_down": {
|
||||
"name": "DSL rate down"
|
||||
},
|
||||
"dsl_rate_up": {
|
||||
"name": "DSL rate up"
|
||||
},
|
||||
"dsl_training": {
|
||||
"name": "DSL training",
|
||||
"state": {
|
||||
"idle": "Idle",
|
||||
"g_994_training": "G.994 Training",
|
||||
|
@ -64,7 +101,23 @@
|
|||
"unknown": "Unknown"
|
||||
}
|
||||
},
|
||||
"net_infra": {
|
||||
"name": "Network infrastructure",
|
||||
"state": {
|
||||
"adsl": "ADSL",
|
||||
"ftth": "FTTH",
|
||||
"gprs": "GPRS",
|
||||
"unknown": "Unknown"
|
||||
}
|
||||
},
|
||||
"temperature": {
|
||||
"name": "[%key:component::sensor::entity_component::temperature::name%]"
|
||||
},
|
||||
"voltage": {
|
||||
"name": "[%key:component::sensor::entity_component::voltage::name%]"
|
||||
},
|
||||
"wan_mode": {
|
||||
"name": "WAN mode",
|
||||
"state": {
|
||||
"adsl_ppp": "ADSL (PPP)",
|
||||
"adsl_routed": "ADSL (Routed)",
|
||||
|
|
|
@ -54,7 +54,7 @@
|
|||
'original_name': 'WAN status',
|
||||
'platform': 'sfr_box',
|
||||
'supported_features': 0,
|
||||
'translation_key': None,
|
||||
'translation_key': 'wan_status',
|
||||
'unique_id': 'e4:5d:51:00:11:22_wan_status',
|
||||
'unit_of_measurement': None,
|
||||
}),
|
||||
|
@ -82,7 +82,7 @@
|
|||
'original_name': 'DSL status',
|
||||
'platform': 'sfr_box',
|
||||
'supported_features': 0,
|
||||
'translation_key': None,
|
||||
'translation_key': 'dsl_status',
|
||||
'unique_id': 'e4:5d:51:00:11:22_dsl_status',
|
||||
'unit_of_measurement': None,
|
||||
}),
|
||||
|
@ -169,7 +169,7 @@
|
|||
'original_name': 'WAN status',
|
||||
'platform': 'sfr_box',
|
||||
'supported_features': 0,
|
||||
'translation_key': None,
|
||||
'translation_key': 'wan_status',
|
||||
'unique_id': 'e4:5d:51:00:11:22_wan_status',
|
||||
'unit_of_measurement': None,
|
||||
}),
|
||||
|
@ -197,7 +197,7 @@
|
|||
'original_name': 'FTTH status',
|
||||
'platform': 'sfr_box',
|
||||
'supported_features': 0,
|
||||
'translation_key': None,
|
||||
'translation_key': 'ftth_status',
|
||||
'unique_id': 'e4:5d:51:00:11:22_ftth_status',
|
||||
'unit_of_measurement': None,
|
||||
}),
|
||||
|
|
|
@ -41,7 +41,7 @@
|
|||
'disabled_by': None,
|
||||
'domain': 'button',
|
||||
'entity_category': <EntityCategory.CONFIG: 'config'>,
|
||||
'entity_id': 'button.sfr_box_reboot',
|
||||
'entity_id': 'button.sfr_box_restart',
|
||||
'has_entity_name': True,
|
||||
'hidden_by': None,
|
||||
'icon': None,
|
||||
|
@ -51,23 +51,23 @@
|
|||
}),
|
||||
'original_device_class': <ButtonDeviceClass.RESTART: 'restart'>,
|
||||
'original_icon': None,
|
||||
'original_name': 'Reboot',
|
||||
'original_name': 'Restart',
|
||||
'platform': 'sfr_box',
|
||||
'supported_features': 0,
|
||||
'translation_key': None,
|
||||
'translation_key': 'reboot',
|
||||
'unique_id': 'e4:5d:51:00:11:22_system_reboot',
|
||||
'unit_of_measurement': None,
|
||||
}),
|
||||
])
|
||||
# ---
|
||||
# name: test_buttons[button.sfr_box_reboot]
|
||||
# name: test_buttons[button.sfr_box_restart]
|
||||
StateSnapshot({
|
||||
'attributes': ReadOnlyDict({
|
||||
'device_class': 'restart',
|
||||
'friendly_name': 'SFR Box Reboot',
|
||||
'friendly_name': 'SFR Box Restart',
|
||||
}),
|
||||
'context': <ANY>,
|
||||
'entity_id': 'button.sfr_box_reboot',
|
||||
'entity_id': 'button.sfr_box_restart',
|
||||
'last_changed': <ANY>,
|
||||
'last_updated': <ANY>,
|
||||
'state': 'unknown',
|
||||
|
|
|
@ -87,7 +87,7 @@
|
|||
'original_name': 'Voltage',
|
||||
'platform': 'sfr_box',
|
||||
'supported_features': 0,
|
||||
'translation_key': None,
|
||||
'translation_key': 'voltage',
|
||||
'unique_id': 'e4:5d:51:00:11:22_system_alimvoltage',
|
||||
'unit_of_measurement': <UnitOfElectricPotential.MILLIVOLT: 'mV'>,
|
||||
}),
|
||||
|
@ -115,7 +115,7 @@
|
|||
'original_name': 'Temperature',
|
||||
'platform': 'sfr_box',
|
||||
'supported_features': 0,
|
||||
'translation_key': None,
|
||||
'translation_key': 'temperature',
|
||||
'unique_id': 'e4:5d:51:00:11:22_system_temperature',
|
||||
'unit_of_measurement': <UnitOfTemperature.CELSIUS: '°C'>,
|
||||
}),
|
||||
|
@ -179,7 +179,7 @@
|
|||
'original_name': 'DSL line mode',
|
||||
'platform': 'sfr_box',
|
||||
'supported_features': 0,
|
||||
'translation_key': None,
|
||||
'translation_key': 'dsl_linemode',
|
||||
'unique_id': 'e4:5d:51:00:11:22_dsl_linemode',
|
||||
'unit_of_measurement': None,
|
||||
}),
|
||||
|
@ -207,7 +207,7 @@
|
|||
'original_name': 'DSL counter',
|
||||
'platform': 'sfr_box',
|
||||
'supported_features': 0,
|
||||
'translation_key': None,
|
||||
'translation_key': 'dsl_counter',
|
||||
'unique_id': 'e4:5d:51:00:11:22_dsl_counter',
|
||||
'unit_of_measurement': None,
|
||||
}),
|
||||
|
@ -235,7 +235,7 @@
|
|||
'original_name': 'DSL CRC',
|
||||
'platform': 'sfr_box',
|
||||
'supported_features': 0,
|
||||
'translation_key': None,
|
||||
'translation_key': 'dsl_crc',
|
||||
'unique_id': 'e4:5d:51:00:11:22_dsl_crc',
|
||||
'unit_of_measurement': None,
|
||||
}),
|
||||
|
@ -265,7 +265,7 @@
|
|||
'original_name': 'DSL noise down',
|
||||
'platform': 'sfr_box',
|
||||
'supported_features': 0,
|
||||
'translation_key': None,
|
||||
'translation_key': 'dsl_noise_down',
|
||||
'unique_id': 'e4:5d:51:00:11:22_dsl_noise_down',
|
||||
'unit_of_measurement': 'dB',
|
||||
}),
|
||||
|
@ -295,7 +295,7 @@
|
|||
'original_name': 'DSL noise up',
|
||||
'platform': 'sfr_box',
|
||||
'supported_features': 0,
|
||||
'translation_key': None,
|
||||
'translation_key': 'dsl_noise_up',
|
||||
'unique_id': 'e4:5d:51:00:11:22_dsl_noise_up',
|
||||
'unit_of_measurement': 'dB',
|
||||
}),
|
||||
|
@ -325,7 +325,7 @@
|
|||
'original_name': 'DSL attenuation down',
|
||||
'platform': 'sfr_box',
|
||||
'supported_features': 0,
|
||||
'translation_key': None,
|
||||
'translation_key': 'dsl_attenuation_down',
|
||||
'unique_id': 'e4:5d:51:00:11:22_dsl_attenuation_down',
|
||||
'unit_of_measurement': 'dB',
|
||||
}),
|
||||
|
@ -355,7 +355,7 @@
|
|||
'original_name': 'DSL attenuation up',
|
||||
'platform': 'sfr_box',
|
||||
'supported_features': 0,
|
||||
'translation_key': None,
|
||||
'translation_key': 'dsl_attenuation_up',
|
||||
'unique_id': 'e4:5d:51:00:11:22_dsl_attenuation_up',
|
||||
'unit_of_measurement': 'dB',
|
||||
}),
|
||||
|
@ -385,7 +385,7 @@
|
|||
'original_name': 'DSL rate down',
|
||||
'platform': 'sfr_box',
|
||||
'supported_features': 0,
|
||||
'translation_key': None,
|
||||
'translation_key': 'dsl_rate_down',
|
||||
'unique_id': 'e4:5d:51:00:11:22_dsl_rate_down',
|
||||
'unit_of_measurement': <UnitOfDataRate.KILOBITS_PER_SECOND: 'kbit/s'>,
|
||||
}),
|
||||
|
@ -415,7 +415,7 @@
|
|||
'original_name': 'DSL rate up',
|
||||
'platform': 'sfr_box',
|
||||
'supported_features': 0,
|
||||
'translation_key': None,
|
||||
'translation_key': 'dsl_rate_up',
|
||||
'unique_id': 'e4:5d:51:00:11:22_dsl_rate_up',
|
||||
'unit_of_measurement': <UnitOfDataRate.KILOBITS_PER_SECOND: 'kbit/s'>,
|
||||
}),
|
||||
|
@ -452,7 +452,7 @@
|
|||
'original_name': 'DSL line status',
|
||||
'platform': 'sfr_box',
|
||||
'supported_features': 0,
|
||||
'translation_key': 'line_status',
|
||||
'translation_key': 'dsl_line_status',
|
||||
'unique_id': 'e4:5d:51:00:11:22_dsl_line_status',
|
||||
'unit_of_measurement': None,
|
||||
}),
|
||||
|
@ -493,7 +493,7 @@
|
|||
'original_name': 'DSL training',
|
||||
'platform': 'sfr_box',
|
||||
'supported_features': 0,
|
||||
'translation_key': 'training',
|
||||
'translation_key': 'dsl_training',
|
||||
'unique_id': 'e4:5d:51:00:11:22_dsl_training',
|
||||
'unit_of_measurement': None,
|
||||
}),
|
||||
|
|
|
@ -56,7 +56,7 @@ async def test_reboot(hass: HomeAssistant, config_entry_with_auth: ConfigEntry)
|
|||
await hass.async_block_till_done()
|
||||
|
||||
# Reboot success
|
||||
service_data = {ATTR_ENTITY_ID: "button.sfr_box_reboot"}
|
||||
service_data = {ATTR_ENTITY_ID: "button.sfr_box_restart"}
|
||||
with patch(
|
||||
"homeassistant.components.sfr_box.button.SFRBox.system_reboot"
|
||||
) as mock_action:
|
||||
|
@ -68,7 +68,7 @@ async def test_reboot(hass: HomeAssistant, config_entry_with_auth: ConfigEntry)
|
|||
assert mock_action.mock_calls[0][1] == ()
|
||||
|
||||
# Reboot failed
|
||||
service_data = {ATTR_ENTITY_ID: "button.sfr_box_reboot"}
|
||||
service_data = {ATTR_ENTITY_ID: "button.sfr_box_restart"}
|
||||
with patch(
|
||||
"homeassistant.components.sfr_box.button.SFRBox.system_reboot",
|
||||
side_effect=SFRBoxError,
|
||||
|
|
Loading…
Add table
Reference in a new issue