Skip to content

Commit 063e146

Browse files
authored
Merge pull request #2 from Shaffer-Softworks/config-flow
Update README and manifest for Android WS Player integration; enhance…
2 parents f6a3f5a + 87c0541 commit 063e146

6 files changed

Lines changed: 56 additions & 17 deletions

File tree

.cursor/rules/android-ws-player.mdc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Home Assistant **custom integration** (HACS-ready) that exposes Android tablets
99

1010
- **Repo**: https://github.com/Shaffer-Softworks/Android-WS-Player
1111
- **Domain**: `android_ws_player`
12-
- **Version**: `0.2.1` (manifest)
12+
- **Version**: `0.2.2` (manifest)
1313
- **Min HA**: `2024.11.0` (`hacs.json`) — required for modern `OptionsFlow`
1414

1515
## Architecture
@@ -61,5 +61,5 @@ Custom-generated artwork (not copied from Android-Management): Android mascot +
6161
| Field | Where | Purpose |
6262
|-------|--------|---------|
6363
| `name` | entry title | Friendly name |
64-
| `device_id` | entry data | Tablet listener ID |
64+
| `device_id` | entry data (editable in options) | Tablet listener / player ID |
6565
| `event_type` | data/options | Bus event name |

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Home Assistant custom integration that exposes each Android tablet as a **media
99

1010
- One media player entity per tablet
1111
- Configurable `device_id` and event type per device
12-
- Rename devices from the integration options (gear icon)
12+
- Edit name, player ID, and event type from the integration options (gear icon)
1313
- `play_media`, `stop`, and `volume_set` support
1414

1515
## Installation
@@ -40,7 +40,7 @@ During setup you provide:
4040
| **Device ID** | Identifier your Android app listens for (e.g. `kitchen_tablet`) |
4141
| **Event type** | HA event name fired for commands (default: `android_ws_player_command`) |
4242

43-
Use the integration **gear icon** to change the name or event type later.
43+
Use the integration **gear icon** to change the name, player ID, or event type later.
4444

4545
## Android app
4646

custom_components/android_ws_player/config_flow.py

Lines changed: 41 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -48,30 +48,59 @@ def async_get_options_flow(config_entry):
4848

4949
class AndroidWsPlayerOptionsFlow(config_entries.OptionsFlow):
5050
async def async_step_init(self, user_input=None):
51+
errors: dict[str, str] = {}
52+
5153
if user_input is not None:
52-
# Update entry title (friendly name shown in UI)
54+
device_id = user_input[CONF_DEVICE_ID].strip()
5355
new_title = user_input["name"].strip()
54-
if new_title and new_title != self.config_entry.title:
55-
self.hass.config_entries.async_update_entry(self.config_entry, title=new_title)
5656

57-
# Store other tunables in options
58-
return self.async_create_entry(
59-
title="",
60-
data={
61-
CONF_EVENT_TYPE: user_input.get(CONF_EVENT_TYPE, DEFAULT_EVENT_TYPE).strip(),
62-
},
63-
)
57+
if not device_id:
58+
errors["base"] = "invalid_device_id"
59+
else:
60+
for entry in self.hass.config_entries.async_entries(DOMAIN):
61+
if (
62+
entry.entry_id != self.config_entry.entry_id
63+
and entry.unique_id == device_id
64+
):
65+
errors[CONF_DEVICE_ID] = "already_configured"
66+
break
67+
68+
if not errors:
69+
data = dict(self.config_entry.data)
70+
data[CONF_DEVICE_ID] = device_id
71+
72+
self.hass.config_entries.async_update_entry(
73+
self.config_entry,
74+
title=new_title or self.config_entry.title,
75+
data=data,
76+
unique_id=device_id,
77+
)
78+
79+
return self.async_create_entry(
80+
title="",
81+
data={
82+
CONF_EVENT_TYPE: user_input.get(
83+
CONF_EVENT_TYPE, DEFAULT_EVENT_TYPE
84+
).strip(),
85+
},
86+
)
6487

6588
schema = vol.Schema(
6689
{
6790
vol.Required("name", default=self.config_entry.title): str,
91+
vol.Required(
92+
CONF_DEVICE_ID, default=self.config_entry.data[CONF_DEVICE_ID]
93+
): str,
6894
vol.Optional(
6995
CONF_EVENT_TYPE,
7096
default=self.config_entry.options.get(
71-
CONF_EVENT_TYPE, self.config_entry.data.get(CONF_EVENT_TYPE, DEFAULT_EVENT_TYPE)
97+
CONF_EVENT_TYPE,
98+
self.config_entry.data.get(CONF_EVENT_TYPE, DEFAULT_EVENT_TYPE),
7299
),
73100
): str,
74101
}
75102
)
76103

77-
return self.async_show_form(step_id="init", data_schema=schema)
104+
return self.async_show_form(
105+
step_id="init", data_schema=schema, errors=errors
106+
)

custom_components/android_ws_player/manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@
77
"iot_class": "local_push",
88
"issue_tracker": "https://github.com/Shaffer-Softworks/Android-WS-Player/issues",
99
"requirements": [],
10-
"version": "0.2.1"
10+
"version": "0.2.2"
1111
}

custom_components/android_ws_player/strings.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,14 @@
2121
"title": "Android WS Player options",
2222
"data": {
2323
"name": "Name",
24+
"device_id": "Player ID",
2425
"event_type": "Event type"
2526
}
2627
}
28+
},
29+
"error": {
30+
"already_configured": "Another entry already uses this player ID.",
31+
"invalid_device_id": "Player ID cannot be empty."
2732
}
2833
}
2934
}

custom_components/android_ws_player/translations/en.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,14 @@
2121
"title": "Android WS Player options",
2222
"data": {
2323
"name": "Name",
24+
"device_id": "Player ID",
2425
"event_type": "Event type"
2526
}
2627
}
28+
},
29+
"error": {
30+
"already_configured": "Another entry already uses this player ID.",
31+
"invalid_device_id": "Player ID cannot be empty."
2732
}
2833
}
2934
}

0 commit comments

Comments
 (0)