Skip to content

Commit 0eef44b

Browse files
authored
Fix inconsistent use of StrEnum as index in MQTT subentry flow globals (home-assistant#154210)
1 parent e7ac56c commit 0eef44b

File tree

1 file changed

+42
-45
lines changed

1 file changed

+42
-45
lines changed

homeassistant/components/mqtt/config_flow.py

Lines changed: 42 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@
109109
STATE_OPEN,
110110
STATE_OPENING,
111111
EntityCategory,
112+
Platform,
112113
UnitOfTemperature,
113114
)
114115
from homeassistant.core import HomeAssistant, async_get_hass, callback
@@ -417,7 +418,6 @@
417418
TRANSPORT_TCP,
418419
TRANSPORT_WEBSOCKETS,
419420
VALUES_ON_COMMAND_TYPE,
420-
Platform,
421421
)
422422
from .models import MqttAvailabilityData, MqttDeviceData, MqttSubentryData
423423
from .util import (
@@ -821,10 +821,7 @@
821821
@callback
822822
def configured_target_temperature_feature(config: dict[str, Any]) -> str:
823823
"""Calculate current target temperature feature from config."""
824-
if (
825-
config == {CONF_PLATFORM: Platform.CLIMATE.value}
826-
or CONF_TEMP_COMMAND_TOPIC in config
827-
):
824+
if config == {CONF_PLATFORM: Platform.CLIMATE} or CONF_TEMP_COMMAND_TOPIC in config:
828825
# default to single on initial set
829826
return "single"
830827
if CONF_TEMP_HIGH_COMMAND_TOPIC in config:
@@ -1156,20 +1153,20 @@ def validate_sensor_platform_config(
11561153
Callable[[dict[str, Any]], dict[str, str]] | None,
11571154
] = {
11581155
Platform.ALARM_CONTROL_PANEL: None,
1159-
Platform.BINARY_SENSOR.value: None,
1160-
Platform.BUTTON.value: None,
1161-
Platform.CLIMATE.value: validate_climate_platform_config,
1162-
Platform.COVER.value: validate_cover_platform_config,
1163-
Platform.FAN.value: validate_fan_platform_config,
1164-
Platform.IMAGE.value: None,
1165-
Platform.LIGHT.value: validate_light_platform_config,
1166-
Platform.LOCK.value: None,
1167-
Platform.NOTIFY.value: None,
1168-
Platform.NUMBER.value: validate_number_platform_config,
1156+
Platform.BINARY_SENSOR: None,
1157+
Platform.BUTTON: None,
1158+
Platform.CLIMATE: validate_climate_platform_config,
1159+
Platform.COVER: validate_cover_platform_config,
1160+
Platform.FAN: validate_fan_platform_config,
1161+
Platform.IMAGE: None,
1162+
Platform.LIGHT: validate_light_platform_config,
1163+
Platform.LOCK: None,
1164+
Platform.NOTIFY: None,
1165+
Platform.NUMBER: validate_number_platform_config,
11691166
Platform.SELECT: None,
1167+
Platform.SENSOR: validate_sensor_platform_config,
11701168
Platform.SIREN: None,
1171-
Platform.SENSOR.value: validate_sensor_platform_config,
1172-
Platform.SWITCH.value: None,
1169+
Platform.SWITCH: None,
11731170
}
11741171

11751172

@@ -1216,8 +1213,8 @@ class PlatformField:
12161213
default=None,
12171214
),
12181215
}
1219-
PLATFORM_ENTITY_FIELDS: dict[str, dict[str, PlatformField]] = {
1220-
Platform.ALARM_CONTROL_PANEL.value: {
1216+
PLATFORM_ENTITY_FIELDS: dict[Platform, dict[str, PlatformField]] = {
1217+
Platform.ALARM_CONTROL_PANEL: {
12211218
CONF_SUPPORTED_FEATURES: PlatformField(
12221219
selector=ALARM_CONTROL_PANEL_FEATURES_SELECTOR,
12231220
required=True,
@@ -1234,7 +1231,7 @@ class PlatformField:
12341231
else "local_code",
12351232
),
12361233
},
1237-
Platform.BINARY_SENSOR.value: {
1234+
Platform.BINARY_SENSOR: {
12381235
CONF_DEVICE_CLASS: PlatformField(
12391236
selector=BINARY_SENSOR_DEVICE_CLASS_SELECTOR,
12401237
required=False,
@@ -1245,13 +1242,13 @@ class PlatformField:
12451242
default=None,
12461243
),
12471244
},
1248-
Platform.BUTTON.value: {
1245+
Platform.BUTTON: {
12491246
CONF_DEVICE_CLASS: PlatformField(
12501247
selector=BUTTON_DEVICE_CLASS_SELECTOR,
12511248
required=False,
12521249
),
12531250
},
1254-
Platform.CLIMATE.value: {
1251+
Platform.CLIMATE: {
12551252
CONF_TEMPERATURE_UNIT: PlatformField(
12561253
selector=TEMPERATURE_UNIT_SELECTOR,
12571254
validator=validate(cv.temperature_unit),
@@ -1323,13 +1320,13 @@ class PlatformField:
13231320
default=lambda config: bool(config.get(CONF_POWER_COMMAND_TOPIC)),
13241321
),
13251322
},
1326-
Platform.COVER.value: {
1323+
Platform.COVER: {
13271324
CONF_DEVICE_CLASS: PlatformField(
13281325
selector=COVER_DEVICE_CLASS_SELECTOR,
13291326
required=False,
13301327
),
13311328
},
1332-
Platform.FAN.value: {
1329+
Platform.FAN: {
13331330
"fan_feature_speed": PlatformField(
13341331
selector=BOOLEAN_SELECTOR,
13351332
required=False,
@@ -1355,7 +1352,7 @@ class PlatformField:
13551352
default=lambda config: bool(config.get(CONF_DIRECTION_COMMAND_TOPIC)),
13561353
),
13571354
},
1358-
Platform.IMAGE.value: {
1355+
Platform.IMAGE: {
13591356
"image_processing_mode": PlatformField(
13601357
selector=IMAGE_PROCESSING_MODE_SELECTOR,
13611358
required=True,
@@ -1367,7 +1364,7 @@ class PlatformField:
13671364
),
13681365
)
13691366
},
1370-
Platform.LIGHT.value: {
1367+
Platform.LIGHT: {
13711368
CONF_SCHEMA: PlatformField(
13721369
selector=LIGHT_SCHEMA_SELECTOR,
13731370
required=True,
@@ -1381,8 +1378,8 @@ class PlatformField:
13811378
is_schema_default=True,
13821379
),
13831380
},
1384-
Platform.LOCK.value: {},
1385-
Platform.NOTIFY.value: {},
1381+
Platform.LOCK: {},
1382+
Platform.NOTIFY: {},
13861383
Platform.NUMBER: {
13871384
CONF_DEVICE_CLASS: PlatformField(
13881385
selector=NUMBER_DEVICE_CLASS_SELECTOR,
@@ -1394,8 +1391,8 @@ class PlatformField:
13941391
custom_filtering=True,
13951392
),
13961393
},
1397-
Platform.SELECT.value: {},
1398-
Platform.SENSOR.value: {
1394+
Platform.SELECT: {},
1395+
Platform.SENSOR: {
13991396
CONF_DEVICE_CLASS: PlatformField(
14001397
selector=SENSOR_DEVICE_CLASS_SELECTOR, required=False
14011398
),
@@ -1425,13 +1422,13 @@ class PlatformField:
14251422
),
14261423
},
14271424
Platform.SIREN: {},
1428-
Platform.SWITCH.value: {
1425+
Platform.SWITCH: {
14291426
CONF_DEVICE_CLASS: PlatformField(
14301427
selector=SWITCH_DEVICE_CLASS_SELECTOR, required=False
14311428
),
14321429
},
14331430
}
1434-
PLATFORM_MQTT_FIELDS: dict[str, dict[str, PlatformField]] = {
1431+
PLATFORM_MQTT_FIELDS: dict[Platform, dict[str, PlatformField]] = {
14351432
Platform.ALARM_CONTROL_PANEL: {
14361433
CONF_COMMAND_TOPIC: PlatformField(
14371434
selector=TEXT_SELECTOR,
@@ -1518,7 +1515,7 @@ class PlatformField:
15181515
section="alarm_control_panel_payload_settings",
15191516
),
15201517
},
1521-
Platform.BINARY_SENSOR.value: {
1518+
Platform.BINARY_SENSOR: {
15221519
CONF_STATE_TOPIC: PlatformField(
15231520
selector=TEXT_SELECTOR,
15241521
required=True,
@@ -1554,7 +1551,7 @@ class PlatformField:
15541551
section="advanced_settings",
15551552
),
15561553
},
1557-
Platform.BUTTON.value: {
1554+
Platform.BUTTON: {
15581555
CONF_COMMAND_TOPIC: PlatformField(
15591556
selector=TEXT_SELECTOR,
15601557
required=True,
@@ -1574,7 +1571,7 @@ class PlatformField:
15741571
),
15751572
CONF_RETAIN: PlatformField(selector=BOOLEAN_SELECTOR, required=False),
15761573
},
1577-
Platform.CLIMATE.value: {
1574+
Platform.CLIMATE: {
15781575
# operation mode settings
15791576
CONF_MODE_COMMAND_TOPIC: PlatformField(
15801577
selector=TEXT_SELECTOR,
@@ -2064,7 +2061,7 @@ class PlatformField:
20642061
conditions=({"climate_feature_swing_horizontal_modes": True},),
20652062
),
20662063
},
2067-
Platform.COVER.value: {
2064+
Platform.COVER: {
20682065
CONF_COMMAND_TOPIC: PlatformField(
20692066
selector=TEXT_SELECTOR,
20702067
required=False,
@@ -2243,7 +2240,7 @@ class PlatformField:
22432240
section="cover_tilt_settings",
22442241
),
22452242
},
2246-
Platform.FAN.value: {
2243+
Platform.FAN: {
22472244
CONF_COMMAND_TOPIC: PlatformField(
22482245
selector=TEXT_SELECTOR,
22492246
required=True,
@@ -2463,7 +2460,7 @@ class PlatformField:
24632460
conditions=({"fan_feature_direction": True},),
24642461
),
24652462
},
2466-
Platform.IMAGE.value: {
2463+
Platform.IMAGE: {
24672464
CONF_IMAGE_TOPIC: PlatformField(
24682465
selector=TEXT_SELECTOR,
24692466
required=True,
@@ -2497,7 +2494,7 @@ class PlatformField:
24972494
error="invalid_template",
24982495
),
24992496
},
2500-
Platform.LIGHT.value: {
2497+
Platform.LIGHT: {
25012498
CONF_COMMAND_TOPIC: PlatformField(
25022499
selector=TEXT_SELECTOR,
25032500
required=True,
@@ -2978,7 +2975,7 @@ class PlatformField:
29782975
section="advanced_settings",
29792976
),
29802977
},
2981-
Platform.LOCK.value: {
2978+
Platform.LOCK: {
29822979
CONF_COMMAND_TOPIC: PlatformField(
29832980
selector=TEXT_SELECTOR,
29842981
required=True,
@@ -3065,7 +3062,7 @@ class PlatformField:
30653062
CONF_RETAIN: PlatformField(selector=BOOLEAN_SELECTOR, required=False),
30663063
CONF_OPTIMISTIC: PlatformField(selector=BOOLEAN_SELECTOR, required=False),
30673064
},
3068-
Platform.NOTIFY.value: {
3065+
Platform.NOTIFY: {
30693066
CONF_COMMAND_TOPIC: PlatformField(
30703067
selector=TEXT_SELECTOR,
30713068
required=True,
@@ -3080,7 +3077,7 @@ class PlatformField:
30803077
),
30813078
CONF_RETAIN: PlatformField(selector=BOOLEAN_SELECTOR, required=False),
30823079
},
3083-
Platform.NUMBER.value: {
3080+
Platform.NUMBER: {
30843081
CONF_COMMAND_TOPIC: PlatformField(
30853082
selector=TEXT_SELECTOR,
30863083
required=True,
@@ -3132,7 +3129,7 @@ class PlatformField:
31323129
),
31333130
CONF_RETAIN: PlatformField(selector=BOOLEAN_SELECTOR, required=False),
31343131
},
3135-
Platform.SELECT.value: {
3132+
Platform.SELECT: {
31363133
CONF_COMMAND_TOPIC: PlatformField(
31373134
selector=TEXT_SELECTOR,
31383135
required=True,
@@ -3160,7 +3157,7 @@ class PlatformField:
31603157
CONF_OPTIONS: PlatformField(selector=OPTIONS_SELECTOR, required=True),
31613158
CONF_RETAIN: PlatformField(selector=BOOLEAN_SELECTOR, required=False),
31623159
},
3163-
Platform.SENSOR.value: {
3160+
Platform.SENSOR: {
31643161
CONF_STATE_TOPIC: PlatformField(
31653162
selector=TEXT_SELECTOR,
31663163
required=True,
@@ -3252,7 +3249,7 @@ class PlatformField:
32523249
section="siren_advanced_settings",
32533250
),
32543251
},
3255-
Platform.SWITCH.value: {
3252+
Platform.SWITCH: {
32563253
CONF_COMMAND_TOPIC: PlatformField(
32573254
selector=TEXT_SELECTOR,
32583255
required=True,

0 commit comments

Comments
 (0)