mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 03:07:37 +00:00
Bump pytrafikverket to 0.3.6 (#99869)
* Bump pytrafikverket to 0.3.6 * Fix config flow names * str
This commit is contained in:
parent
74a7bccd65
commit
e425662494
@ -10,7 +10,7 @@ from pytrafikverket.exceptions import (
|
|||||||
NoCameraFound,
|
NoCameraFound,
|
||||||
UnknownError,
|
UnknownError,
|
||||||
)
|
)
|
||||||
from pytrafikverket.trafikverket_camera import TrafikverketCamera
|
from pytrafikverket.trafikverket_camera import CameraInfo, TrafikverketCamera
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
from homeassistant import config_entries
|
from homeassistant import config_entries
|
||||||
@ -29,14 +29,17 @@ class TVCameraConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
|||||||
|
|
||||||
entry: config_entries.ConfigEntry | None
|
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."""
|
"""Validate input from user input."""
|
||||||
errors: dict[str, str] = {}
|
errors: dict[str, str] = {}
|
||||||
|
camera_info: CameraInfo | None = None
|
||||||
|
|
||||||
web_session = async_get_clientsession(self.hass)
|
web_session = async_get_clientsession(self.hass)
|
||||||
camera_api = TrafikverketCamera(web_session, sensor_api)
|
camera_api = TrafikverketCamera(web_session, sensor_api)
|
||||||
try:
|
try:
|
||||||
await camera_api.async_get_camera(location)
|
camera_info = await camera_api.async_get_camera(location)
|
||||||
except NoCameraFound:
|
except NoCameraFound:
|
||||||
errors["location"] = "invalid_location"
|
errors["location"] = "invalid_location"
|
||||||
except MultipleCamerasFound:
|
except MultipleCamerasFound:
|
||||||
@ -46,7 +49,8 @@ class TVCameraConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
|||||||
except UnknownError:
|
except UnknownError:
|
||||||
errors["base"] = "cannot_connect"
|
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:
|
async def async_step_reauth(self, entry_data: Mapping[str, Any]) -> FlowResult:
|
||||||
"""Handle re-authentication with Trafikverket."""
|
"""Handle re-authentication with Trafikverket."""
|
||||||
@ -58,13 +62,15 @@ class TVCameraConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
|||||||
self, user_input: dict[str, Any] | None = None
|
self, user_input: dict[str, Any] | None = None
|
||||||
) -> FlowResult:
|
) -> FlowResult:
|
||||||
"""Confirm re-authentication with Trafikverket."""
|
"""Confirm re-authentication with Trafikverket."""
|
||||||
errors = {}
|
errors: dict[str, str] = {}
|
||||||
|
|
||||||
if user_input:
|
if user_input:
|
||||||
api_key = user_input[CONF_API_KEY]
|
api_key = user_input[CONF_API_KEY]
|
||||||
|
|
||||||
assert self.entry is not None
|
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:
|
if not errors:
|
||||||
self.hass.config_entries.async_update_entry(
|
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
|
self, user_input: dict[str, str] | None = None
|
||||||
) -> FlowResult:
|
) -> FlowResult:
|
||||||
"""Handle the initial step."""
|
"""Handle the initial step."""
|
||||||
errors = {}
|
errors: dict[str, str] = {}
|
||||||
|
|
||||||
if user_input:
|
if user_input:
|
||||||
api_key = user_input[CONF_API_KEY]
|
api_key = user_input[CONF_API_KEY]
|
||||||
location = user_input[CONF_LOCATION]
|
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:
|
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()
|
self._abort_if_unique_id_configured()
|
||||||
return self.async_create_entry(
|
return self.async_create_entry(
|
||||||
title=user_input[CONF_LOCATION],
|
title=camera_location,
|
||||||
data={
|
data={
|
||||||
CONF_API_KEY: api_key,
|
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",
|
"documentation": "https://www.home-assistant.io/integrations/trafikverket_camera",
|
||||||
"iot_class": "cloud_polling",
|
"iot_class": "cloud_polling",
|
||||||
"loggers": ["pytrafikverket"],
|
"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",
|
"documentation": "https://www.home-assistant.io/integrations/trafikverket_ferry",
|
||||||
"iot_class": "cloud_polling",
|
"iot_class": "cloud_polling",
|
||||||
"loggers": ["pytrafikverket"],
|
"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",
|
"documentation": "https://www.home-assistant.io/integrations/trafikverket_train",
|
||||||
"iot_class": "cloud_polling",
|
"iot_class": "cloud_polling",
|
||||||
"loggers": ["pytrafikverket"],
|
"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",
|
"documentation": "https://www.home-assistant.io/integrations/trafikverket_weatherstation",
|
||||||
"iot_class": "cloud_polling",
|
"iot_class": "cloud_polling",
|
||||||
"loggers": ["pytrafikverket"],
|
"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_ferry
|
||||||
# homeassistant.components.trafikverket_train
|
# homeassistant.components.trafikverket_train
|
||||||
# homeassistant.components.trafikverket_weatherstation
|
# homeassistant.components.trafikverket_weatherstation
|
||||||
pytrafikverket==0.3.5
|
pytrafikverket==0.3.6
|
||||||
|
|
||||||
# homeassistant.components.usb
|
# homeassistant.components.usb
|
||||||
pyudev==0.23.2
|
pyudev==0.23.2
|
||||||
|
@ -1619,7 +1619,7 @@ pytradfri[async]==9.0.1
|
|||||||
# homeassistant.components.trafikverket_ferry
|
# homeassistant.components.trafikverket_ferry
|
||||||
# homeassistant.components.trafikverket_train
|
# homeassistant.components.trafikverket_train
|
||||||
# homeassistant.components.trafikverket_weatherstation
|
# homeassistant.components.trafikverket_weatherstation
|
||||||
pytrafikverket==0.3.5
|
pytrafikverket==0.3.6
|
||||||
|
|
||||||
# homeassistant.components.usb
|
# homeassistant.components.usb
|
||||||
pyudev==0.23.2
|
pyudev==0.23.2
|
||||||
|
@ -10,6 +10,7 @@ from pytrafikverket.exceptions import (
|
|||||||
NoCameraFound,
|
NoCameraFound,
|
||||||
UnknownError,
|
UnknownError,
|
||||||
)
|
)
|
||||||
|
from pytrafikverket.trafikverket_camera import CameraInfo
|
||||||
|
|
||||||
from homeassistant import config_entries
|
from homeassistant import config_entries
|
||||||
from homeassistant.components.trafikverket_camera.const import CONF_LOCATION, DOMAIN
|
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
|
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."""
|
"""Test we get the form."""
|
||||||
|
|
||||||
result = await hass.config_entries.flow.async_init(
|
result = await hass.config_entries.flow.async_init(
|
||||||
@ -31,6 +32,7 @@ async def test_form(hass: HomeAssistant) -> None:
|
|||||||
|
|
||||||
with patch(
|
with patch(
|
||||||
"homeassistant.components.trafikverket_camera.config_flow.TrafikverketCamera.async_get_camera",
|
"homeassistant.components.trafikverket_camera.config_flow.TrafikverketCamera.async_get_camera",
|
||||||
|
return_value=get_camera,
|
||||||
), patch(
|
), patch(
|
||||||
"homeassistant.components.trafikverket_camera.async_setup_entry",
|
"homeassistant.components.trafikverket_camera.async_setup_entry",
|
||||||
return_value=True,
|
return_value=True,
|
||||||
@ -39,7 +41,7 @@ async def test_form(hass: HomeAssistant) -> None:
|
|||||||
result["flow_id"],
|
result["flow_id"],
|
||||||
{
|
{
|
||||||
CONF_API_KEY: "1234567890",
|
CONF_API_KEY: "1234567890",
|
||||||
CONF_LOCATION: "Test location",
|
CONF_LOCATION: "Test loc",
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user