Make location types in co2signal translatable (#102127)

This commit is contained in:
Jan-Philipp Benecke 2023-10-16 23:13:14 +02:00 committed by GitHub
parent 4130980100
commit f891fb6b41
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 8 deletions

View File

@ -9,15 +9,20 @@ from homeassistant import config_entries
from homeassistant.const import CONF_API_KEY, CONF_LATITUDE, CONF_LONGITUDE from homeassistant.const import CONF_API_KEY, CONF_LATITUDE, CONF_LONGITUDE
from homeassistant.data_entry_flow import FlowResult from homeassistant.data_entry_flow import FlowResult
import homeassistant.helpers.config_validation as cv import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.selector import (
SelectSelector,
SelectSelectorConfig,
SelectSelectorMode,
)
from .const import CONF_COUNTRY_CODE, DOMAIN from .const import CONF_COUNTRY_CODE, DOMAIN
from .coordinator import get_data from .coordinator import get_data
from .exceptions import APIRatelimitExceeded, InvalidAuth from .exceptions import APIRatelimitExceeded, InvalidAuth
from .util import get_extra_name from .util import get_extra_name
TYPE_USE_HOME = "Use home location" TYPE_USE_HOME = "use_home_location"
TYPE_SPECIFY_COORDINATES = "Specify coordinates" TYPE_SPECIFY_COORDINATES = "specify_coordinates"
TYPE_SPECIFY_COUNTRY = "Specify country code" TYPE_SPECIFY_COUNTRY = "specify_country_code"
class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN): class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
@ -32,11 +37,15 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
"""Handle the initial step.""" """Handle the initial step."""
data_schema = vol.Schema( data_schema = vol.Schema(
{ {
vol.Required("location", default=TYPE_USE_HOME): vol.In( vol.Required("location"): SelectSelector(
( SelectSelectorConfig(
TYPE_USE_HOME, translation_key="location",
TYPE_SPECIFY_COORDINATES, mode=SelectSelectorMode.LIST,
TYPE_SPECIFY_COUNTRY, options=[
TYPE_USE_HOME,
TYPE_SPECIFY_COORDINATES,
TYPE_SPECIFY_COUNTRY,
],
) )
), ),
vol.Required(CONF_API_KEY): cv.string, vol.Required(CONF_API_KEY): cv.string,

View File

@ -50,5 +50,14 @@
} }
} }
} }
},
"selector": {
"location": {
"options": {
"use_home_location": "Use home location",
"specify_coordinates": "Specify coordinates",
"specify_country_code": "Specify country code"
}
}
} }
} }