Make Matter select entity values translatable (#126608)

* Make Matter select entity values lowercase

* Make Matter select entity values lowercase
This commit is contained in:
Joost Lekkerkerker 2024-09-24 13:40:38 +02:00 committed by GitHub
parent 9e703b8224
commit d3889cab9e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 20 additions and 14 deletions

View file

@ -228,18 +228,18 @@ DISCOVERY_SCHEMAS = [
key="MatterStartUpOnOff",
entity_category=EntityCategory.CONFIG,
translation_key="startup_on_off",
options=["On", "Off", "Toggle", "Previous"],
options=["on", "off", "toggle", "previous"],
measurement_to_ha={
0: "Off",
1: "On",
2: "Toggle",
None: "Previous",
0: "off",
1: "on",
2: "toggle",
None: "previous",
}.get,
ha_to_native_value={
"Off": 0,
"On": 1,
"Toggle": 2,
"Previous": None,
"off": 0,
"on": 1,
"toggle": 2,
"previous": None,
}.get,
),
entity_class=MatterSelectEntity,

View file

@ -136,7 +136,13 @@
"name": "Mode"
},
"startup_on_off": {
"name": "Power-on behavior on Startup"
"name": "Power-on behavior on startup",
"state": {
"on": "[%key:common::state::on%]",
"off": "[%key:common::state::off%]",
"toggle": "[%key:common::action::toggle%]",
"previous": "Previous"
}
}
},
"sensor": {

View file

@ -87,16 +87,16 @@ async def test_attribute_select_entities(
entity_id = "select.mock_dimmable_light_power_on_behavior_on_startup"
state = hass.states.get(entity_id)
assert state
assert state.state == "Previous"
assert state.attributes["options"] == ["On", "Off", "Toggle", "Previous"]
assert state.state == "previous"
assert state.attributes["options"] == ["on", "off", "toggle", "previous"]
assert (
state.attributes["friendly_name"]
== "Mock Dimmable Light Power-on behavior on Startup"
== "Mock Dimmable Light Power-on behavior on startup"
)
set_node_attribute(light_node, 1, 6, 16387, 1)
await trigger_subscription_callback(hass, matter_client)
state = hass.states.get(entity_id)
assert state.state == "On"
assert state.state == "on"
# test that an invalid value (e.g. 255) leads to an unknown state
set_node_attribute(light_node, 1, 6, 16387, 255)
await trigger_subscription_callback(hass, matter_client)