Skip to content

Commit

Permalink
Added channels to constants
Browse files Browse the repository at this point in the history
  • Loading branch information
Dmitry Mamontov committed Apr 20, 2022
1 parent f950aa3 commit 3385b76
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 4 deletions.
40 changes: 40 additions & 0 deletions custom_components/miwifi/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,14 +166,54 @@
ATTR_SELECT_WIFI_2_4_CHANNEL: Final = "wifi_2_4_channel"
ATTR_SELECT_WIFI_2_4_CHANNELS: Final = "wifi_2_4_channels"
ATTR_SELECT_WIFI_2_4_CHANNEL_NAME: Final = f"{ATTR_WIFI_NAME} 2.4G channel"
ATTR_SELECT_WIFI_2_4_CHANNEL_OPTIONS: Final = [
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9",
"10",
"11",
"12",
"13"
]

ATTR_SELECT_WIFI_5_0_CHANNEL: Final = "wifi_5_0_channel"
ATTR_SELECT_WIFI_5_0_CHANNELS: Final = "wifi_5_0_channels"
ATTR_SELECT_WIFI_5_0_CHANNEL_NAME: Final = f"{ATTR_WIFI_NAME} 5G channel"
ATTR_SELECT_WIFI_5_0_CHANNEL_OPTIONS: Final = [
"36",
"40",
"44",
"48",
"52",
"56",
"60",
"64",
"149",
"153",
"157",
"161",
"165"
]

ATTR_SELECT_WIFI_5_0_GAME_CHANNEL: Final = "wifi_5_0_game_channel"
ATTR_SELECT_WIFI_5_0_GAME_CHANNELS: Final = "wifi_5_0_game_channels"
ATTR_SELECT_WIFI_5_0_GAME_CHANNEL_NAME: Final = f"{ATTR_WIFI_NAME} 5G game channel"
ATTR_SELECT_WIFI_5_0_GAME_CHANNEL_OPTIONS: Final = [
"36",
"40",
"44",
"48",
"52",
"56",
"60",
"64"
]

ATTR_SELECT_SIGNAL_STRENGTH_OPTIONS: Final = ["min", "mid", "max"]

Expand Down
2 changes: 1 addition & 1 deletion custom_components/miwifi/manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"domain": "miwifi",
"name": "MiWiFi",
"version": "2.4.4",
"version": "2.4.5",
"documentation": "https://github.com/dmamontov/hass-miwifi/blob/main/README.md",
"issue_tracker": "https://github.com/dmamontov/hass-miwifi/issues",
"config_flow": true,
Expand Down
24 changes: 21 additions & 3 deletions custom_components/miwifi/select.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,14 @@
ATTR_SELECT_WIFI_2_4_CHANNEL,
ATTR_SELECT_WIFI_2_4_CHANNELS,
ATTR_SELECT_WIFI_2_4_CHANNEL_NAME,
ATTR_SELECT_WIFI_2_4_CHANNEL_OPTIONS,
ATTR_SELECT_WIFI_5_0_CHANNEL,
ATTR_SELECT_WIFI_5_0_CHANNEL_NAME,
ATTR_SELECT_WIFI_5_0_CHANNEL_OPTIONS,
ATTR_SELECT_WIFI_5_0_CHANNELS,
ATTR_SELECT_WIFI_5_0_GAME_CHANNEL,
ATTR_SELECT_WIFI_5_0_GAME_CHANNEL_NAME,
ATTR_SELECT_WIFI_5_0_GAME_CHANNEL_OPTIONS,
ATTR_SELECT_WIFI_5_0_GAME_CHANNELS,
ATTR_SELECT_SIGNAL_STRENGTH_OPTIONS,
ATTR_SELECT_WIFI_2_4_SIGNAL_STRENGTH,
Expand Down Expand Up @@ -65,6 +68,9 @@
}

OPTIONS_MAP: Final = {
ATTR_SELECT_WIFI_2_4_CHANNEL: ATTR_SELECT_WIFI_2_4_CHANNEL_OPTIONS,
ATTR_SELECT_WIFI_5_0_CHANNEL: ATTR_SELECT_WIFI_5_0_CHANNEL_OPTIONS,
ATTR_SELECT_WIFI_5_0_GAME_CHANNEL: ATTR_SELECT_WIFI_5_0_GAME_CHANNEL_OPTIONS,
ATTR_SELECT_WIFI_2_4_SIGNAL_STRENGTH: ATTR_SELECT_SIGNAL_STRENGTH_OPTIONS,
ATTR_SELECT_WIFI_5_0_SIGNAL_STRENGTH: ATTR_SELECT_SIGNAL_STRENGTH_OPTIONS,
ATTR_SELECT_WIFI_5_0_GAME_SIGNAL_STRENGTH: ATTR_SELECT_SIGNAL_STRENGTH_OPTIONS,
Expand Down Expand Up @@ -209,11 +215,23 @@ def __init__(
self._attr_current_option = updater.data.get(description.key, None)
self._change_icon(self._attr_current_option)

if description.key in OPTIONS_MAP:
self._attr_options = OPTIONS_MAP[description.key]
else:
self._attr_options = []
if description.key in CHANNELS_MAP:
self._attr_options = updater.data.get(CHANNELS_MAP[description.key], [])

if description.key in OPTIONS_MAP and len(self._attr_options) == 0:
if (
updater.data.get(ATTR_WIFI_ADAPTER_LENGTH, 2) > 2
and description.key == ATTR_SELECT_WIFI_5_0_CHANNEL
):
self._attr_options = [
option
for option in OPTIONS_MAP[description.key]
if option not in OPTIONS_MAP[ATTR_SELECT_WIFI_5_0_GAME_CHANNEL]
]
else:
self._attr_options = OPTIONS_MAP[description.key]

if description.key in DATA_MAP:
self._wifi_data = updater.data.get(DATA_MAP[description.key], {})
else:
Expand Down

0 comments on commit 3385b76

Please sign in to comment.