Bump pytrafikverket to 0.3.6 (#99869)
* Bump pytrafikverket to 0.3.6 * Fix config flow names * strpull/99989/head
parent
74a7bccd65
commit
e425662494
|
@ -10,7 +10,7 @@ from pytrafikverket.exceptions import (
|
|||
NoCameraFound,
|
||||
UnknownError,
|
||||
)
|
||||
from pytrafikverket.trafikverket_camera import TrafikverketCamera
|
||||
from pytrafikverket.trafikverket_camera import CameraInfo, TrafikverketCamera
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant import config_entries
|
||||
|
@ -29,14 +29,17 @@ class TVCameraConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
|||
|
||||
entry: config_entries.ConfigEntry | None
|
||||
|
||||
async def validate_input(self, sensor_api: str, location: str) -> dict[str, str]:
|
||||
async def validate_input(
|
||||
self, sensor_api: str, location: str
|
||||
) -> tuple[dict[str, str], str | None]:
|
||||
"""Validate input from user input."""
|
||||
errors: dict[str, str] = {}
|
||||
camera_info: CameraInfo | None = None
|
||||
|
||||
web_session = async_get_clientsession(self.hass)
|
||||
camera_api = TrafikverketCamera(web_session, sensor_api)
|
||||
try:
|
||||
await camera_api.async_get_camera(location)
|
||||
camera_info = await camera_api.async_get_camera(location)
|
||||
except NoCameraFound:
|
||||
errors["location"] = "invalid_location"
|
||||
except MultipleCamerasFound:
|
||||
|
@ -46,7 +49,8 @@ class TVCameraConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
|||
except UnknownError:
|
||||
errors["base"] = "cannot_connect"
|
||||
|
||||
return errors
|
||||
camera_location = camera_info.location if camera_info else None
|
||||
return (errors, camera_location)
|
||||
|
||||
async def async_step_reauth(self, entry_data: Mapping[str, Any]) -> FlowResult:
|
||||
"""Handle re-authentication with Trafikverket."""
|
||||
|
@ -58,13 +62,15 @@ class TVCameraConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
|||
self, user_input: dict[str, Any] | None = None
|
||||
) -> FlowResult:
|
||||
"""Confirm re-authentication with Trafikverket."""
|
||||
errors = {}
|
||||
errors: dict[str, str] = {}
|
||||
|
||||
if user_input:
|
||||
api_key = user_input[CONF_API_KEY]
|
||||
|
||||
assert self.entry is not None
|
||||
errors = await self.validate_input(api_key, self.entry.data[CONF_LOCATION])
|
||||
errors, _ = await self.validate_input(
|
||||
api_key, self.entry.data[CONF_LOCATION]
|
||||
)
|
||||
|
||||
if not errors:
|
||||
self.hass.config_entries.async_update_entry(
|
||||
|
@ -91,22 +97,23 @@ class TVCameraConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
|||
self, user_input: dict[str, str] | None = None
|
||||
) -> FlowResult:
|
||||
"""Handle the initial step."""
|
||||
errors = {}
|
||||
errors: dict[str, str] = {}
|
||||
|
||||
if user_input:
|
||||
api_key = user_input[CONF_API_KEY]
|
||||
location = user_input[CONF_LOCATION]
|
||||
|
||||
errors = await self.validate_input(api_key, location)
|
||||
errors, camera_location = await self.validate_input(api_key, location)
|
||||
|
||||
if not errors:
|
||||
await self.async_set_unique_id(f"{DOMAIN}-{location}")
|
||||
assert camera_location
|
||||
await self.async_set_unique_id(f"{DOMAIN}-{camera_location}")
|
||||
self._abort_if_unique_id_configured()
|
||||
return self.async_create_entry(
|
||||
title=user_input[CONF_LOCATION],
|
||||
title=camera_location,
|
||||
data={
|
||||
CONF_API_KEY: api_key,
|
||||
CONF_LOCATION: location,
|
||||
CONF_LOCATION: camera_location,
|
||||
},
|
||||
)
|
||||
|
||||
|
|
|
@ -6,5 +6,5 @@
|
|||
"documentation": "https://www.home-assistant.io/integrations/trafikverket_camera",
|
||||
"iot_class": "cloud_polling",
|
||||
"loggers": ["pytrafikverket"],
|
||||
"requirements": ["pytrafikverket==0.3.5"]
|
||||
"requirements": ["pytrafikverket==0.3.6"]
|
||||
}
|
||||
|
|
|
@ -6,5 +6,5 @@
|
|||
"documentation": "https://www.home-assistant.io/integrations/trafikverket_ferry",
|
||||
"iot_class": "cloud_polling",
|
||||
"loggers": ["pytrafikverket"],
|
||||
"requirements": ["pytrafikverket==0.3.5"]
|
||||
"requirements": ["pytrafikverket==0.3.6"]
|
||||
}
|
||||
|
|
|
@ -6,5 +6,5 @@
|
|||
"documentation": "https://www.home-assistant.io/integrations/trafikverket_train",
|
||||
"iot_class": "cloud_polling",
|
||||
"loggers": ["pytrafikverket"],
|
||||
"requirements": ["pytrafikverket==0.3.5"]
|
||||
"requirements": ["pytrafikverket==0.3.6"]
|
||||
}
|
||||
|
|
|
@ -6,5 +6,5 @@
|
|||
"documentation": "https://www.home-assistant.io/integrations/trafikverket_weatherstation",
|
||||
"iot_class": "cloud_polling",
|
||||
"loggers": ["pytrafikverket"],
|
||||
"requirements": ["pytrafikverket==0.3.5"]
|
||||
"requirements": ["pytrafikverket==0.3.6"]
|
||||
}
|
||||
|
|
|
@ -2199,7 +2199,7 @@ pytradfri[async]==9.0.1
|
|||
# homeassistant.components.trafikverket_ferry
|
||||
# homeassistant.components.trafikverket_train
|
||||
# homeassistant.components.trafikverket_weatherstation
|
||||
pytrafikverket==0.3.5
|
||||
pytrafikverket==0.3.6
|
||||
|
||||
# homeassistant.components.usb
|
||||
pyudev==0.23.2
|
||||
|
|
|
@ -1619,7 +1619,7 @@ pytradfri[async]==9.0.1
|
|||
# homeassistant.components.trafikverket_ferry
|
||||
# homeassistant.components.trafikverket_train
|
||||
# homeassistant.components.trafikverket_weatherstation
|
||||
pytrafikverket==0.3.5
|
||||
pytrafikverket==0.3.6
|
||||
|
||||
# homeassistant.components.usb
|
||||
pyudev==0.23.2
|
||||
|
|
|
@ -10,6 +10,7 @@ from pytrafikverket.exceptions import (
|
|||
NoCameraFound,
|
||||
UnknownError,
|
||||
)
|
||||
from pytrafikverket.trafikverket_camera import CameraInfo
|
||||
|
||||
from homeassistant import config_entries
|
||||
from homeassistant.components.trafikverket_camera.const import CONF_LOCATION, DOMAIN
|
||||
|
@ -20,7 +21,7 @@ from homeassistant.data_entry_flow import FlowResultType
|
|||
from tests.common import MockConfigEntry
|
||||
|
||||
|
||||
async def test_form(hass: HomeAssistant) -> None:
|
||||
async def test_form(hass: HomeAssistant, get_camera: CameraInfo) -> None:
|
||||
"""Test we get the form."""
|
||||
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
|
@ -31,6 +32,7 @@ async def test_form(hass: HomeAssistant) -> None:
|
|||
|
||||
with patch(
|
||||
"homeassistant.components.trafikverket_camera.config_flow.TrafikverketCamera.async_get_camera",
|
||||
return_value=get_camera,
|
||||
), patch(
|
||||
"homeassistant.components.trafikverket_camera.async_setup_entry",
|
||||
return_value=True,
|
||||
|
@ -39,7 +41,7 @@ async def test_form(hass: HomeAssistant) -> None:
|
|||
result["flow_id"],
|
||||
{
|
||||
CONF_API_KEY: "1234567890",
|
||||
CONF_LOCATION: "Test location",
|
||||
CONF_LOCATION: "Test loc",
|
||||
},
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
|
Loading…
Reference in New Issue