Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to translate ENUM sensor states in Unifi integration #131921

Merged
merged 5 commits into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions homeassistant/components/unifi/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,17 +50,17 @@
OUTLET_SWITCH = "outlet"

DEVICE_STATES = {
DeviceState.DISCONNECTED: "Disconnected",
DeviceState.CONNECTED: "Connected",
DeviceState.PENDING: "Pending",
DeviceState.FIRMWARE_MISMATCH: "Firmware Mismatch",
DeviceState.UPGRADING: "Upgrading",
DeviceState.PROVISIONING: "Provisioning",
DeviceState.HEARTBEAT_MISSED: "Heartbeat Missed",
DeviceState.ADOPTING: "Adopting",
DeviceState.DELETING: "Deleting",
DeviceState.INFORM_ERROR: "Inform Error",
DeviceState.ADOPTION_FALIED: "Adoption Failed",
DeviceState.ISOLATED: "Isolated",
DeviceState.UNKNOWN: "Unknown",
DeviceState.DISCONNECTED: "disconnected",
DeviceState.CONNECTED: "connected",
DeviceState.PENDING: "pending",
DeviceState.FIRMWARE_MISMATCH: "firmware_mismatch",
DeviceState.UPGRADING: "upgrading",
DeviceState.PROVISIONING: "provisioning",
DeviceState.HEARTBEAT_MISSED: "heartbeat_missed",
DeviceState.ADOPTING: "adopting",
DeviceState.DELETING: "deleting",
DeviceState.INFORM_ERROR: "inform_error",
DeviceState.ADOPTION_FALIED: "adoption_failed",
DeviceState.ISOLATED: "isolated",
DeviceState.UNKNOWN: "unknown",
}
21 changes: 21 additions & 0 deletions homeassistant/components/unifi/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,27 @@
"reauth_successful": "[%key:common::config_flow::abort::reauth_successful%]"
}
},
"entity": {
"sensor": {
"device_state": {
"state": {
"disconnected": "Disconnected",
"connected": "Connected",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couldn't some states have references to already existing translations?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"disconnected": "Disconnected",
"connected": "Connected",
"disconnected": "[%key:common::state::disconnected%]",
"connected": "[%key:common::state::connected%]",

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, forgot about that.

"pending": "Pending",
"firmware_mismatch": "Firmware Mismatch",
"upgrading": "Upgrading",
"provisioning": "Provisioning",
"heartbeat_missed": "Heartbeat Missed",
"adopting": "Adopting",
"deleting": "Deleting",
"inform_error": "Inform Error",
"adoption_failed": "Adoption Failed",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use sentence case

"isolated": "Isolated",
"unknown": "Unknown"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unknown should not be its own state. Rather, the entity should return None in that case (which for the end user would still resolve to unknown, but the difference is, is that unknown already is a valid state and shown in the automation editor)

}
}
}
},
"options": {
"abort": {
"integration_not_setup": "UniFi integration is not set up"
Expand Down
162 changes: 81 additions & 81 deletions tests/components/unifi/snapshots/test_sensor.ambr
Original file line number Diff line number Diff line change
Expand Up @@ -55,19 +55,19 @@
'area_id': None,
'capabilities': dict({
'options': list([
'Disconnected',
'Connected',
'Pending',
'Firmware Mismatch',
'Upgrading',
'Provisioning',
'Heartbeat Missed',
'Adopting',
'Deleting',
'Inform Error',
'Adoption Failed',
'Isolated',
'Unknown',
'disconnected',
'connected',
'pending',
'firmware_mismatch',
'upgrading',
'provisioning',
'heartbeat_missed',
'adopting',
'deleting',
'inform_error',
'adoption_failed',
'isolated',
'unknown',
]),
}),
'config_entry_id': <ANY>,
Expand Down Expand Up @@ -103,27 +103,27 @@
'device_class': 'enum',
'friendly_name': 'Device State',
'options': list([
'Disconnected',
'Connected',
'Pending',
'Firmware Mismatch',
'Upgrading',
'Provisioning',
'Heartbeat Missed',
'Adopting',
'Deleting',
'Inform Error',
'Adoption Failed',
'Isolated',
'Unknown',
'disconnected',
'connected',
'pending',
'firmware_mismatch',
'upgrading',
'provisioning',
'heartbeat_missed',
'adopting',
'deleting',
'inform_error',
'adoption_failed',
'isolated',
'unknown',
]),
}),
'context': <ANY>,
'entity_id': 'sensor.device_state',
'last_changed': <ANY>,
'last_reported': <ANY>,
'last_updated': <ANY>,
'state': 'Connected',
'state': 'connected',
})
# ---
# name: test_entity_and_device_data[wlan_payload0-device_payload0-client_payload0-config_entry_options0][sensor.device_temperature-entry]
Expand Down Expand Up @@ -536,19 +536,19 @@
'area_id': None,
'capabilities': dict({
'options': list([
'Disconnected',
'Connected',
'Pending',
'Firmware Mismatch',
'Upgrading',
'Provisioning',
'Heartbeat Missed',
'Adopting',
'Deleting',
'Inform Error',
'Adoption Failed',
'Isolated',
'Unknown',
'disconnected',
'connected',
'pending',
'firmware_mismatch',
'upgrading',
'provisioning',
'heartbeat_missed',
'adopting',
'deleting',
'inform_error',
'adoption_failed',
'isolated',
'unknown',
]),
}),
'config_entry_id': <ANY>,
Expand Down Expand Up @@ -584,27 +584,27 @@
'device_class': 'enum',
'friendly_name': 'Dummy USP-PDU-Pro State',
'options': list([
'Disconnected',
'Connected',
'Pending',
'Firmware Mismatch',
'Upgrading',
'Provisioning',
'Heartbeat Missed',
'Adopting',
'Deleting',
'Inform Error',
'Adoption Failed',
'Isolated',
'Unknown',
'disconnected',
'connected',
'pending',
'firmware_mismatch',
'upgrading',
'provisioning',
'heartbeat_missed',
'adopting',
'deleting',
'inform_error',
'adoption_failed',
'isolated',
'unknown',
]),
}),
'context': <ANY>,
'entity_id': 'sensor.dummy_usp_pdu_pro_state',
'last_changed': <ANY>,
'last_reported': <ANY>,
'last_updated': <ANY>,
'state': 'Connected',
'state': 'connected',
})
# ---
# name: test_entity_and_device_data[wlan_payload0-device_payload0-client_payload0-config_entry_options0][sensor.dummy_usp_pdu_pro_uptime-entry]
Expand Down Expand Up @@ -1601,19 +1601,19 @@
'area_id': None,
'capabilities': dict({
'options': list([
'Disconnected',
'Connected',
'Pending',
'Firmware Mismatch',
'Upgrading',
'Provisioning',
'Heartbeat Missed',
'Adopting',
'Deleting',
'Inform Error',
'Adoption Failed',
'Isolated',
'Unknown',
'disconnected',
'connected',
'pending',
'firmware_mismatch',
'upgrading',
'provisioning',
'heartbeat_missed',
'adopting',
'deleting',
'inform_error',
'adoption_failed',
'isolated',
'unknown',
]),
}),
'config_entry_id': <ANY>,
Expand Down Expand Up @@ -1649,27 +1649,27 @@
'device_class': 'enum',
'friendly_name': 'mock-name State',
'options': list([
'Disconnected',
'Connected',
'Pending',
'Firmware Mismatch',
'Upgrading',
'Provisioning',
'Heartbeat Missed',
'Adopting',
'Deleting',
'Inform Error',
'Adoption Failed',
'Isolated',
'Unknown',
'disconnected',
'connected',
'pending',
'firmware_mismatch',
'upgrading',
'provisioning',
'heartbeat_missed',
'adopting',
'deleting',
'inform_error',
'adoption_failed',
'isolated',
'unknown',
]),
}),
'context': <ANY>,
'entity_id': 'sensor.mock_name_state',
'last_changed': <ANY>,
'last_reported': <ANY>,
'last_updated': <ANY>,
'state': 'Connected',
'state': 'connected',
})
# ---
# name: test_entity_and_device_data[wlan_payload0-device_payload0-client_payload0-config_entry_options0][sensor.mock_name_uptime-entry]
Expand Down