Skip to content

Commit ccd93aa

Browse files
authored
Merge branch 'dev' into tado-duc
2 parents 2d37b03 + 57b7635 commit ccd93aa

File tree

20 files changed

+274
-34
lines changed

20 files changed

+274
-34
lines changed

homeassistant/components/russound_rio/config_flow.py

Lines changed: 52 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,13 @@
88
from aiorussound import RussoundClient, RussoundTcpConnectionHandler
99
import voluptuous as vol
1010

11+
from homeassistant.components import zeroconf
1112
from homeassistant.config_entries import (
1213
SOURCE_RECONFIGURE,
1314
ConfigFlow,
1415
ConfigFlowResult,
1516
)
16-
from homeassistant.const import CONF_HOST, CONF_PORT
17+
from homeassistant.const import CONF_HOST, CONF_NAME, CONF_PORT
1718
from homeassistant.helpers import config_validation as cv
1819

1920
from .const import DOMAIN, RUSSOUND_RIO_EXCEPTIONS
@@ -33,6 +34,53 @@ class FlowHandler(ConfigFlow, domain=DOMAIN):
3334

3435
VERSION = 1
3536

37+
def __init__(self) -> None:
38+
"""Initialize the config flow."""
39+
self.data: dict[str, Any] = {}
40+
41+
async def async_step_zeroconf(
42+
self, discovery_info: zeroconf.ZeroconfServiceInfo
43+
) -> ConfigFlowResult:
44+
"""Handle zeroconf discovery."""
45+
self.data[CONF_HOST] = host = discovery_info.host
46+
self.data[CONF_PORT] = port = discovery_info.port or 9621
47+
48+
client = RussoundClient(RussoundTcpConnectionHandler(host, port))
49+
try:
50+
await client.connect()
51+
controller = client.controllers[1]
52+
await client.disconnect()
53+
except RUSSOUND_RIO_EXCEPTIONS:
54+
return self.async_abort(reason="cannot_connect")
55+
56+
await self.async_set_unique_id(controller.mac_address)
57+
self._abort_if_unique_id_configured(updates={CONF_HOST: host})
58+
59+
self.data[CONF_NAME] = controller.controller_type
60+
61+
self.context["title_placeholders"] = {
62+
"name": self.data[CONF_NAME],
63+
}
64+
return await self.async_step_discovery_confirm()
65+
66+
async def async_step_discovery_confirm(
67+
self, user_input: dict[str, Any] | None = None
68+
) -> ConfigFlowResult:
69+
"""Confirm discovery."""
70+
if user_input is not None:
71+
return self.async_create_entry(
72+
title=self.data[CONF_NAME],
73+
data={CONF_HOST: self.data[CONF_HOST], CONF_PORT: self.data[CONF_PORT]},
74+
)
75+
76+
self._set_confirm_only()
77+
return self.async_show_form(
78+
step_id="discovery_confirm",
79+
description_placeholders={
80+
"name": self.data[CONF_NAME],
81+
},
82+
)
83+
3684
async def async_step_user(
3785
self, user_input: dict[str, Any] | None = None
3886
) -> ConfigFlowResult:
@@ -51,7 +99,9 @@ async def async_step_user(
5199
_LOGGER.exception("Could not connect to Russound RIO")
52100
errors["base"] = "cannot_connect"
53101
else:
54-
await self.async_set_unique_id(controller.mac_address)
102+
await self.async_set_unique_id(
103+
controller.mac_address, raise_on_progress=False
104+
)
55105
if self.source == SOURCE_RECONFIGURE:
56106
self._abort_if_unique_id_mismatch(reason="wrong_device")
57107
return self.async_update_reload_and_abort(

homeassistant/components/russound_rio/manifest.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,6 @@
77
"iot_class": "local_push",
88
"loggers": ["aiorussound"],
99
"quality_scale": "silver",
10-
"requirements": ["aiorussound==4.2.0"]
10+
"requirements": ["aiorussound==4.2.0"],
11+
"zeroconf": ["_rio._tcp.local."]
1112
}

homeassistant/components/russound_rio/quality_scale.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ rules:
5757
status: exempt
5858
comment: |
5959
This integration doesn't have enough / noisy entities that warrant being disabled by default.
60-
discovery: todo
60+
discovery: done
6161
stale-devices: todo
6262
diagnostics: done
6363
exception-translations: done
@@ -67,7 +67,7 @@ rules:
6767
There are no entities that require icons.
6868
reconfiguration-flow: done
6969
dynamic-devices: todo
70-
discovery-update-info: todo
70+
discovery-update-info: done
7171
repair-issues:
7272
status: exempt
7373
comment: |

homeassistant/components/russound_rio/strings.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515
"port": "The port of the Russound controller."
1616
}
1717
},
18+
"discovery_confirm": {
19+
"description": "Do you want to setup {name}?"
20+
},
1821
"reconfigure": {
1922
"description": "Reconfigure your Russound controller.",
2023
"data": {

homeassistant/components/trafikverket_camera/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,12 @@ async def async_setup_entry(hass: HomeAssistant, entry: TVCameraConfigEntry) ->
3434
return True
3535

3636

37-
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
37+
async def async_unload_entry(hass: HomeAssistant, entry: TVCameraConfigEntry) -> bool:
3838
"""Unload Trafikverket Camera config entry."""
3939
return await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
4040

4141

42-
async def async_migrate_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
42+
async def async_migrate_entry(hass: HomeAssistant, entry: TVCameraConfigEntry) -> bool:
4343
"""Migrate old entry."""
4444
api_key = entry.data[CONF_API_KEY]
4545
web_session = async_get_clientsession(hass)

homeassistant/components/trafikverket_camera/camera.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
from .coordinator import TVDataUpdateCoordinator
1616
from .entity import TrafikverketCameraEntity
1717

18+
PARALLEL_UPDATES = 0
19+
1820

1921
async def async_setup_entry(
2022
hass: HomeAssistant,

homeassistant/components/trafikverket_ferry/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@
1414
async def async_setup_entry(hass: HomeAssistant, entry: TVFerryConfigEntry) -> bool:
1515
"""Set up Trafikverket Ferry from a config entry."""
1616

17-
coordinator = TVDataUpdateCoordinator(hass)
17+
coordinator = TVDataUpdateCoordinator(hass, entry)
1818
await coordinator.async_config_entry_first_refresh()
1919
entry.runtime_data = coordinator
2020
await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
2121

2222
return True
2323

2424

25-
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
25+
async def async_unload_entry(hass: HomeAssistant, entry: TVFerryConfigEntry) -> bool:
2626
"""Unload Trafikverket Ferry config entry."""
2727
return await hass.config_entries.async_unload_platforms(entry, PLATFORMS)

homeassistant/components/trafikverket_ferry/coordinator.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,21 +52,22 @@ class TVDataUpdateCoordinator(DataUpdateCoordinator):
5252

5353
config_entry: TVFerryConfigEntry
5454

55-
def __init__(self, hass: HomeAssistant) -> None:
55+
def __init__(self, hass: HomeAssistant, config_entry: TVFerryConfigEntry) -> None:
5656
"""Initialize the Trafikverket coordinator."""
5757
super().__init__(
5858
hass,
5959
_LOGGER,
60+
config_entry=config_entry,
6061
name=DOMAIN,
6162
update_interval=TIME_BETWEEN_UPDATES,
6263
)
6364
self._ferry_api = TrafikverketFerry(
64-
async_get_clientsession(hass), self.config_entry.data[CONF_API_KEY]
65+
async_get_clientsession(hass), config_entry.data[CONF_API_KEY]
6566
)
66-
self._from: str = self.config_entry.data[CONF_FROM]
67-
self._to: str = self.config_entry.data[CONF_TO]
68-
self._time: time | None = dt_util.parse_time(self.config_entry.data[CONF_TIME])
69-
self._weekdays: list[str] = self.config_entry.data[CONF_WEEKDAY]
67+
self._from: str = config_entry.data[CONF_FROM]
68+
self._to: str = config_entry.data[CONF_TO]
69+
self._time: time | None = dt_util.parse_time(config_entry.data[CONF_TIME])
70+
self._weekdays: list[str] = config_entry.data[CONF_WEEKDAY]
7071

7172
async def _async_update_data(self) -> dict[str, Any]:
7273
"""Fetch data from Trafikverket."""

homeassistant/components/trafikverket_ferry/sensor.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131

3232
SCAN_INTERVAL = timedelta(minutes=5)
3333

34+
PARALLEL_UPDATES = 0
35+
3436

3537
@dataclass(frozen=True, kw_only=True)
3638
class TrafikverketSensorEntityDescription(SensorEntityDescription):

homeassistant/components/trafikverket_train/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
async def async_setup_entry(hass: HomeAssistant, entry: TVTrainConfigEntry) -> bool:
2020
"""Set up Trafikverket Train from a config entry."""
2121

22-
coordinator = TVDataUpdateCoordinator(hass)
22+
coordinator = TVDataUpdateCoordinator(hass, entry)
2323
await coordinator.async_config_entry_first_refresh()
2424
entry.runtime_data = coordinator
2525

@@ -37,13 +37,13 @@ async def async_setup_entry(hass: HomeAssistant, entry: TVTrainConfigEntry) -> b
3737
return True
3838

3939

40-
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
40+
async def async_unload_entry(hass: HomeAssistant, entry: TVTrainConfigEntry) -> bool:
4141
"""Unload Trafikverket Weatherstation config entry."""
4242

4343
return await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
4444

4545

46-
async def update_listener(hass: HomeAssistant, entry: ConfigEntry) -> None:
46+
async def update_listener(hass: HomeAssistant, entry: TVTrainConfigEntry) -> None:
4747
"""Handle options update."""
4848
await hass.config_entries.async_reload(entry.entry_id)
4949

0 commit comments

Comments
 (0)