Skip to content

Commit 7af985c

Browse files
author
Tom Lasswell
committed
refactor: Simplify segment mode configuration - remove global setting
- Remove global segment_mode option from options flow - Use per-device segment mode configuration only with SEGMENT_MODE_INDIVIDUAL default - Add friendly labels for per-device segment mode dropdowns - Simplify light.py and __init__.py to use per-device-only mode resolution - Remove unused imports and debug logging references - Update strings.json and translations/en.json accordingly This simplifies the UI by removing redundant global setting and focusing on per-device configuration when needed.
1 parent e27948e commit 7af985c

File tree

6 files changed

+22
-42
lines changed

6 files changed

+22
-42
lines changed

custom_components/govee/__init__.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,11 @@
2525
CONF_ENABLE_SEGMENTS,
2626
CONF_PASSWORD,
2727
CONF_POLL_INTERVAL,
28-
CONF_SEGMENT_MODE,
2928
DEFAULT_ENABLE_DIY_SCENES,
3029
DEFAULT_ENABLE_GROUPS,
3130
DEFAULT_ENABLE_SCENES,
3231
DEFAULT_ENABLE_SEGMENTS,
3332
DEFAULT_POLL_INTERVAL,
34-
DEFAULT_SEGMENT_MODE,
3533
DOMAIN,
3634
KEY_IOT_CREDENTIALS,
3735
KEY_IOT_LOGIN_FAILED,
@@ -261,16 +259,14 @@ async def _async_cleanup_orphaned_entities(
261259

262260
# Get current options
263261
options = entry.options
264-
global_segment_mode = options.get(CONF_SEGMENT_MODE, DEFAULT_SEGMENT_MODE)
265262
device_modes = options.get("segment_mode_by_device", {})
266263
# For backward compatibility, check old enable_segments boolean
267264
enable_segments_old = options.get(CONF_ENABLE_SEGMENTS, DEFAULT_ENABLE_SEGMENTS)
268265
enable_scenes = options.get(CONF_ENABLE_SCENES, DEFAULT_ENABLE_SCENES)
269266
enable_diy_scenes = options.get(CONF_ENABLE_DIY_SCENES, DEFAULT_ENABLE_DIY_SCENES)
270267

271268
_LOGGER.debug(
272-
"Orphan cleanup: global_segment_mode=%s, device_modes=%s, enable_scenes=%s, enable_diy_scenes=%s",
273-
global_segment_mode,
269+
"Orphan cleanup: device_modes=%s, enable_scenes=%s, enable_diy_scenes=%s",
274270
len(device_modes),
275271
enable_scenes,
276272
enable_diy_scenes,
@@ -302,8 +298,8 @@ async def _async_cleanup_orphaned_entities(
302298

303299
# Check feature toggles first
304300
if device_id:
305-
# Get per-device mode, fallback to global
306-
segment_mode = device_modes.get(device_id, global_segment_mode)
301+
# Get per-device mode (default to individual)
302+
segment_mode = device_modes.get(device_id, SEGMENT_MODE_INDIVIDUAL)
307303
suffix = unique_id[len(device_id) :]
308304

309305
# Use explicit suffix matching to avoid false positives

custom_components/govee/config_flow.py

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -488,13 +488,6 @@ async def async_step_init(
488488
CONF_ENABLE_DIY_SCENES, DEFAULT_ENABLE_DIY_SCENES
489489
),
490490
): bool,
491-
vol.Optional(
492-
CONF_SEGMENT_MODE,
493-
default=options.get(
494-
CONF_SEGMENT_MODE,
495-
SEGMENT_MODE_INDIVIDUAL if options.get(CONF_ENABLE_SEGMENTS, DEFAULT_ENABLE_SEGMENTS) else SEGMENT_MODE_DISABLED,
496-
),
497-
): vol.In([SEGMENT_MODE_DISABLED, SEGMENT_MODE_GROUPED, SEGMENT_MODE_INDIVIDUAL]),
498491
}
499492
),
500493
)
@@ -567,15 +560,21 @@ async def async_step_configure_device_modes(
567560
schema_dict: dict[vol.Marker, vol.Schema] = {}
568561

569562
current_device_modes = self._config_entry.options.get("segment_mode_by_device", {})
570-
global_mode = self._global_options.get(CONF_SEGMENT_MODE, DEFAULT_SEGMENT_MODE)
563+
564+
# Friendly labels for segment modes
565+
mode_options = {
566+
SEGMENT_MODE_DISABLED: "Disabled (hide segment entities)",
567+
SEGMENT_MODE_GROUPED: "Grouped (control all together)",
568+
SEGMENT_MODE_INDIVIDUAL: "Individual (separate control per segment)",
569+
}
571570

572571
for device_id in self._selected_devices:
573572
device = coordinator.devices.get(device_id)
574573
if not device:
575574
continue
576575

577-
# Get current mode for this device
578-
default_mode = current_device_modes.get(device_id, global_mode)
576+
# Get current mode for this device (default to individual)
577+
default_mode = current_device_modes.get(device_id, SEGMENT_MODE_INDIVIDUAL)
579578

580579
# Create field key and label for this device
581580
field_key = f"segment_mode_{device_id}"
@@ -585,7 +584,7 @@ async def async_step_configure_device_modes(
585584
field_key,
586585
description=device_label,
587586
default=default_mode,
588-
)] = vol.In([SEGMENT_MODE_DISABLED, SEGMENT_MODE_GROUPED, SEGMENT_MODE_INDIVIDUAL])
587+
)] = vol.In(mode_options)
589588

590589
_LOGGER.debug("Showing per-device configuration form for %d devices", len(self._selected_devices))
591590

custom_components/govee/light.py

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@
2626
from homeassistant.helpers.restore_state import RestoreEntity
2727

2828
from .const import (
29-
CONF_SEGMENT_MODE,
30-
DEFAULT_SEGMENT_MODE,
3129
SEGMENT_MODE_DISABLED,
3230
SEGMENT_MODE_GROUPED,
3331
SEGMENT_MODE_INDIVIDUAL,
@@ -61,25 +59,23 @@ async def async_setup_entry(
6159

6260
entities: list[LightEntity] = []
6361

64-
# Get per-device and global segment modes
62+
# Get per-device segment modes
6563
device_modes = entry.options.get("segment_mode_by_device", {})
66-
global_segment_mode = entry.options.get(CONF_SEGMENT_MODE, DEFAULT_SEGMENT_MODE)
6764

6865
for device in coordinator.devices.values():
6966
# Only create light entities for devices with power control (not fans)
7067
if device.supports_power and not device.is_fan:
7168
entities.append(GoveeLightEntity(coordinator, device))
7269

73-
# Create segment entities for RGBIC devices based on per-device or global mode
70+
# Create segment entities for RGBIC devices based on per-device mode
7471
if device.supports_segments and device.segment_count > 0:
75-
# Get per-device mode, fallback to global
76-
segment_mode = device_modes.get(device.device_id, global_segment_mode)
72+
# Use per-device mode if set, otherwise default to individual
73+
segment_mode = device_modes.get(device.device_id, SEGMENT_MODE_INDIVIDUAL)
7774

7875
_LOGGER.debug(
79-
"Segment check for %s: device_mode=%s, global_mode=%s, supports_segments=%s, segment_count=%d",
76+
"Segment check for %s: device_mode=%s, supports_segments=%s, segment_count=%d",
8077
device.name,
81-
device_modes.get(device.device_id, "not set"),
82-
global_segment_mode,
78+
device_modes.get(device.device_id, "default (individual)"),
8379
device.supports_segments,
8480
device.segment_count,
8581
)

custom_components/govee/manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,6 @@
1616
"cryptography>=41.0.0"
1717
],
1818
"ssdp": [],
19-
"version": "2026.2.5",
19+
"version": "2026.2.6",
2020
"zeroconf": []
2121
}

custom_components/govee/strings.json

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -68,21 +68,11 @@
6868
"poll_interval": "Polling interval (seconds)",
6969
"enable_groups": "Enable group devices",
7070
"enable_scenes": "Enable scene selector",
71-
"enable_diy_scenes": "Enable DIY scene selector",
72-
"segment_mode": "Segment control mode"
71+
"enable_diy_scenes": "Enable DIY scene selector"
7372
}
7473
}
7574
}
7675
},
77-
"selector": {
78-
"segment_mode": {
79-
"options": {
80-
"disabled": "Disabled (no segment entities)",
81-
"grouped": "Grouped (single control for all segments)",
82-
"individual": "Individual (separate control for each segment)"
83-
}
84-
}
85-
},
8676
"entity": {
8777
"light": {
8878
"govee_light": {

custom_components/govee/translations/en.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,7 @@
6868
"poll_interval": "Polling interval (seconds)",
6969
"enable_groups": "Enable group devices",
7070
"enable_scenes": "Enable scene selector",
71-
"enable_diy_scenes": "Enable DIY scene selector",
72-
"enable_segments": "Enable segment entities"
71+
"enable_diy_scenes": "Enable DIY scene selector"
7372
}
7473
}
7574
}

0 commit comments

Comments
 (0)