diff --git a/custom_components/meteobridgesql/config_flow.py b/custom_components/meteobridgesql/config_flow.py index 8eda522..e507d3e 100644 --- a/custom_components/meteobridgesql/config_flow.py +++ b/custom_components/meteobridgesql/config_flow.py @@ -14,7 +14,7 @@ ) from homeassistant.core import callback from homeassistant.data_entry_flow import FlowResult -from pymeteobridgesql import MeteobridgeSQL, MeteobridgeSQLDatabaseConnectionError +from pymeteobridgesql import MeteobridgeSQL, MeteobridgeSQLDatabaseConnectionError, MeteobridgeSQLDataError, StationData from .const import (CONF_DATABASE, DEFAULT_PORT, DOMAIN) _LOGGER = logging.getLogger(__name__) @@ -41,16 +41,21 @@ async def async_step_user(self, user_input: dict[str, Any] | None = None) -> Flo try: meteobridge = MeteobridgeSQL(host=user_input[CONF_HOST],user=user_input[CONF_USERNAME],password=user_input[CONF_PASSWORD], database=user_input[CONF_DATABASE]) await meteobridge.async_init() + station_data: StationData = await meteobridge.async_get_station_data(user_input[CONF_MAC]) except MeteobridgeSQLDatabaseConnectionError as error: _LOGGER.error("Error connecting to MySQL Database: %s", error) errors["base"] = "cannot_connect" return await self._show_setup_form(errors) + except MeteobridgeSQLDataError as error: + _LOGGER.error("Failed to lookup data in the database: %s", error) + errors["base"] = "no_data" + return await self._show_setup_form(errors) await self.async_set_unique_id(user_input[CONF_MAC]) self._abort_if_unique_id_configured return self.async_create_entry( - title=f"Meteobride SQL ({user_input[CONF_MAC]})", + title=f"Meteobride SQL ({station_data.mb_stationname})", data={ CONF_MAC: user_input[CONF_MAC], CONF_HOST: user_input[CONF_HOST], diff --git a/custom_components/meteobridgesql/sensor.py b/custom_components/meteobridgesql/sensor.py index 5b156a0..3c50e05 100644 --- a/custom_components/meteobridgesql/sensor.py +++ b/custom_components/meteobridgesql/sensor.py @@ -254,7 +254,7 @@ def __init__( entry_type=DeviceEntryType.SERVICE, manufacturer=MANUFACTURER, model=_get_hw_platform(self.coordinator.data.sensor_data.mb_platform), - name=f"{self.coordinator.data.sensor_data.mb_stationname} Sensors", + name=f"{self.coordinator.data.sensor_data.mb_stationname} Sensor", configuration_url=f"http://{self.coordinator.data.sensor_data.mb_ip}", hw_version=f"{self.coordinator.data.sensor_data.mb_platform}", sw_version=f"{self.coordinator.data.sensor_data.mb_swversion}-{self.coordinator.data.sensor_data.mb_buildnum}", diff --git a/custom_components/meteobridgesql/translations/en.json b/custom_components/meteobridgesql/translations/en.json index 7adf0bb..77d060b 100644 --- a/custom_components/meteobridgesql/translations/en.json +++ b/custom_components/meteobridgesql/translations/en.json @@ -4,7 +4,8 @@ "unique_id": "This Server has already been setup." }, "error": { - "cannot_connect": "Cannot connect to the MySQL Database. Please check your input and try again" + "cannot_connect": "Cannot connect to the MySQL Database. Please check your input and try again.", + "no_data": "Cannot retrieve data from the database. Does the table exist?" }, "step": { "user": {