Skip to content

Commit e6279d7

Browse files
author
Ted Roberts
committed
Add configurable pre-populated layer source select count (v0.2.26)
1 parent f95df99 commit e6279d7

6 files changed

Lines changed: 40 additions & 7 deletions

File tree

custom_components/novastar_h/config_flow.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,12 @@
1414
from .const import (
1515
CONF_ALLOW_RAW_COMMANDS,
1616
CONF_ENCRYPTION,
17+
CONF_LAYER_SELECT_PREPOPULATE_COUNT,
1718
CONF_PROJECT_ID,
1819
CONF_SECRET_KEY,
1920
DEFAULT_ALLOW_RAW_COMMANDS,
2021
DEFAULT_ENCRYPTION,
22+
DEFAULT_LAYER_SELECT_PREPOPULATE_COUNT,
2123
DEFAULT_NAME,
2224
DEFAULT_PORT,
2325
DOMAIN,
@@ -335,6 +337,13 @@ async def async_step_init(
335337
CONF_ALLOW_RAW_COMMANDS,
336338
self.config_entry.data.get(CONF_ALLOW_RAW_COMMANDS, DEFAULT_ALLOW_RAW_COMMANDS),
337339
)
340+
current_layer_count = self.config_entry.options.get(
341+
CONF_LAYER_SELECT_PREPOPULATE_COUNT,
342+
self.config_entry.data.get(
343+
CONF_LAYER_SELECT_PREPOPULATE_COUNT,
344+
DEFAULT_LAYER_SELECT_PREPOPULATE_COUNT,
345+
),
346+
)
338347

339348
return self.async_show_form(
340349
step_id="init",
@@ -343,6 +352,10 @@ async def async_step_init(
343352
vol.Optional(
344353
CONF_ALLOW_RAW_COMMANDS, default=current_allow_raw
345354
): bool,
355+
vol.Optional(
356+
CONF_LAYER_SELECT_PREPOPULATE_COUNT,
357+
default=current_layer_count,
358+
): vol.All(vol.Coerce(int), vol.Range(min=1, max=16)),
346359
}
347360
),
348361
)

custom_components/novastar_h/const.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,13 @@
1414
CONF_SECRET_KEY = "secret_key"
1515
CONF_ENCRYPTION = "encryption"
1616
CONF_ALLOW_RAW_COMMANDS = "allow_raw_commands"
17+
CONF_LAYER_SELECT_PREPOPULATE_COUNT = "layer_select_prepopulate_count"
1718

1819
DEFAULT_DEVICE_ID = 0
1920
DEFAULT_SCREEN_ID = 0
2021
DEFAULT_ENCRYPTION = False
2122
DEFAULT_ALLOW_RAW_COMMANDS = False
23+
DEFAULT_LAYER_SELECT_PREPOPULATE_COUNT = 4
2224

2325
PLATFORMS: list[Platform] = [
2426
Platform.SWITCH,

custom_components/novastar_h/manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,5 @@
2121
}
2222
],
2323
"zeroconf": ["_novastar._tcp.local."],
24-
"version": "0.2.25"
24+
"version": "0.2.26"
2525
}

custom_components/novastar_h/select.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,12 @@
1010
from homeassistant.helpers.update_coordinator import CoordinatorEntity
1111

1212
from .api import NovastarDeviceInfo
13-
from .const import DEFAULT_NAME, DOMAIN
13+
from .const import (
14+
CONF_LAYER_SELECT_PREPOPULATE_COUNT,
15+
DEFAULT_LAYER_SELECT_PREPOPULATE_COUNT,
16+
DEFAULT_NAME,
17+
DOMAIN,
18+
)
1419
from .coordinator import NovastarCoordinator
1520

1621

@@ -66,11 +71,20 @@ async def async_setup_entry(
6671
"""Set up Novastar select entities."""
6772
coordinator: NovastarCoordinator = hass.data[DOMAIN][entry.entry_id]["coordinator"]
6873
device_info: NovastarDeviceInfo = hass.data[DOMAIN][entry.entry_id]["device_info"]
74+
layer_count = entry.options.get(
75+
CONF_LAYER_SELECT_PREPOPULATE_COUNT,
76+
entry.data.get(
77+
CONF_LAYER_SELECT_PREPOPULATE_COUNT,
78+
DEFAULT_LAYER_SELECT_PREPOPULATE_COUNT,
79+
),
80+
)
81+
layer_count = _coerce_int(layer_count) or DEFAULT_LAYER_SELECT_PREPOPULATE_COUNT
82+
6983
entities: list[SelectEntity] = [NovastarPresetSelect(entry, coordinator, device_info)]
7084
entities.extend(
7185
[
7286
NovastarLayerSourceSelect(entry, coordinator, device_info, layer_id)
73-
for layer_id in range(4)
87+
for layer_id in range(max(1, layer_count))
7488
]
7589
)
7690
async_add_entities(entities)

custom_components/novastar_h/strings.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,12 @@
9090
"init": {
9191
"title": "Novastar Options",
9292
"data": {
93-
"allow_raw_commands": "Allow Raw Commands"
93+
"allow_raw_commands": "Allow Raw Commands",
94+
"layer_select_prepopulate_count": "Number of Layers to pre-populate for input selection"
9495
},
9596
"data_description": {
96-
"allow_raw_commands": "Enable sending raw API commands via service call"
97+
"allow_raw_commands": "Enable sending raw API commands via service call",
98+
"layer_select_prepopulate_count": "How many fixed Layer X Source select entities to create"
9799
}
98100
}
99101
}

custom_components/novastar_h/translations/en.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,12 @@
9090
"init": {
9191
"title": "Novastar Options",
9292
"data": {
93-
"allow_raw_commands": "Allow Raw Commands"
93+
"allow_raw_commands": "Allow Raw Commands",
94+
"layer_select_prepopulate_count": "Number of Layers to pre-populate for input selection"
9495
},
9596
"data_description": {
96-
"allow_raw_commands": "Enable sending raw API commands via service call"
97+
"allow_raw_commands": "Enable sending raw API commands via service call",
98+
"layer_select_prepopulate_count": "How many fixed Layer X Source select entities to create"
9799
}
98100
}
99101
}

0 commit comments

Comments
 (0)