Skip to content

Commit

Permalink
feat: Radio button for region (#448)
Browse files Browse the repository at this point in the history
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Kolbi <[email protected]>
  • Loading branch information
3 people authored Jul 24, 2024
1 parent 42067fb commit 1669f67
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
7 changes: 4 additions & 3 deletions custom_components/audiconnect/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
MIN_UPDATE_INTERVAL,
CONF_SCAN_INITIAL,
CONF_SCAN_ACTIVE,
REGIONS,
)

_LOGGER = logging.getLogger(__name__)
Expand Down Expand Up @@ -52,7 +53,7 @@ async def async_step_user(self, user_input=None):
self._username = user_input[CONF_USERNAME]
self._password = user_input[CONF_PASSWORD]
self._spin = user_input.get(CONF_SPIN)
self._region = user_input.get(CONF_REGION)
self._region = REGIONS[user_input.get(CONF_REGION)]
self._scan_interval = user_input[CONF_SCAN_INTERVAL]

try:
Expand Down Expand Up @@ -94,7 +95,7 @@ async def async_step_user(self, user_input=None):
data_schema[vol.Required(CONF_USERNAME, default=self._username)] = str
data_schema[vol.Required(CONF_PASSWORD, default=self._password)] = str
data_schema[vol.Optional(CONF_SPIN, default=self._spin)] = str
data_schema[vol.Optional(CONF_REGION, default=self._region)] = str
data_schema[vol.Required(CONF_REGION, default=self._region)] = vol.In(REGIONS)
data_schema[
vol.Optional(CONF_SCAN_INTERVAL, default=DEFAULT_UPDATE_INTERVAL)
] = int
Expand All @@ -116,7 +117,7 @@ async def async_step_import(self, user_input):

region = "DE"
if user_input.get(CONF_REGION):
region = user_input.get(CONF_REGION)
region = REGIONS[user_input.get(CONF_REGION)]

scan_interval = DEFAULT_UPDATE_INTERVAL

Expand Down
12 changes: 12 additions & 0 deletions custom_components/audiconnect/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,15 @@
"device_tracker": "device_tracker",
"switch": "switch",
}

REGION_EUROPE: str = "DE"
REGION_CANADA: str = "CA"
REGION_USA: str = "US"
REGION_CHINA: str = "CN"

REGIONS = {
1: REGION_EUROPE,
2: REGION_CANADA,
3: REGION_USA,
4: REGION_CHINA,
}
4 changes: 2 additions & 2 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ Configuration is done through the Home Assistant UI.

To add the integration, go to **Settings ➤ Devices & Services ➤ Integrations**, click **➕ Add Integration**, and search for "Audi Connect".

![Configuration](ha_config.png)
![image](https://github.com/user-attachments/assets/facff84e-f40f-4090-9e44-80f698385426)

### Configuration Variables

Expand All @@ -62,7 +62,7 @@ To add the integration, go to **Settings ➤ Devices & Services ➤ Integrations

**region**

- (string)(Optional) The region where your Audi Connect account is registered.
- (string)(Required) The region where your Audi Connect account is registered.
- 'DE' for Europe (or leave unset)
- 'US' for United States of America
- 'CA' for Canada
Expand Down

0 comments on commit 1669f67

Please sign in to comment.