Add country code constant (#105640)
This commit is contained in:
parent
816a37f9fc
commit
e4453ace88
19 changed files with 40 additions and 45 deletions
|
@ -10,19 +10,13 @@ import voluptuous as vol
|
|||
|
||||
from homeassistant.components.camera import Camera
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import CONF_LATITUDE, CONF_LONGITUDE
|
||||
from homeassistant.const import CONF_COUNTRY_CODE, CONF_LATITUDE, CONF_LONGITUDE
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
from homeassistant.util import dt as dt_util
|
||||
|
||||
from .const import (
|
||||
CONF_COUNTRY,
|
||||
CONF_DELTA,
|
||||
DEFAULT_COUNTRY,
|
||||
DEFAULT_DELTA,
|
||||
DEFAULT_DIMENSION,
|
||||
)
|
||||
from .const import CONF_DELTA, DEFAULT_COUNTRY, DEFAULT_DELTA, DEFAULT_DIMENSION
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
@ -40,7 +34,9 @@ async def async_setup_entry(
|
|||
config = entry.data
|
||||
options = entry.options
|
||||
|
||||
country = options.get(CONF_COUNTRY, config.get(CONF_COUNTRY, DEFAULT_COUNTRY))
|
||||
country = options.get(
|
||||
CONF_COUNTRY_CODE, config.get(CONF_COUNTRY_CODE, DEFAULT_COUNTRY)
|
||||
)
|
||||
|
||||
delta = options.get(CONF_DELTA, config.get(CONF_DELTA, DEFAULT_DELTA))
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@ import voluptuous as vol
|
|||
|
||||
from homeassistant import config_entries
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import CONF_LATITUDE, CONF_LONGITUDE
|
||||
from homeassistant.const import CONF_COUNTRY_CODE, CONF_LATITUDE, CONF_LONGITUDE
|
||||
from homeassistant.core import callback
|
||||
from homeassistant.data_entry_flow import FlowResult
|
||||
from homeassistant.helpers import selector
|
||||
|
@ -20,7 +20,6 @@ from homeassistant.helpers.schema_config_entry_flow import (
|
|||
)
|
||||
|
||||
from .const import (
|
||||
CONF_COUNTRY,
|
||||
CONF_DELTA,
|
||||
CONF_TIMEFRAME,
|
||||
DEFAULT_COUNTRY,
|
||||
|
@ -32,7 +31,9 @@ from .const import (
|
|||
|
||||
OPTIONS_SCHEMA = vol.Schema(
|
||||
{
|
||||
vol.Optional(CONF_COUNTRY, default=DEFAULT_COUNTRY): selector.CountrySelector(
|
||||
vol.Optional(
|
||||
CONF_COUNTRY_CODE, default=DEFAULT_COUNTRY
|
||||
): selector.CountrySelector(
|
||||
selector.CountrySelectorConfig(countries=SUPPORTED_COUNTRY_CODES)
|
||||
),
|
||||
vol.Optional(CONF_DELTA, default=DEFAULT_DELTA): selector.NumberSelector(
|
||||
|
|
|
@ -8,7 +8,6 @@ DEFAULT_DIMENSION = 700
|
|||
DEFAULT_DELTA = 600
|
||||
|
||||
CONF_DELTA = "delta"
|
||||
CONF_COUNTRY = "country_code"
|
||||
CONF_TIMEFRAME = "timeframe"
|
||||
|
||||
SUPPORTED_COUNTRY_CODES = ["NL", "BE"]
|
||||
|
|
|
@ -10,7 +10,12 @@ import voluptuous as vol
|
|||
|
||||
from homeassistant import config_entries
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import CONF_API_KEY, CONF_LATITUDE, CONF_LONGITUDE
|
||||
from homeassistant.const import (
|
||||
CONF_API_KEY,
|
||||
CONF_COUNTRY_CODE,
|
||||
CONF_LATITUDE,
|
||||
CONF_LONGITUDE,
|
||||
)
|
||||
from homeassistant.data_entry_flow import FlowResult
|
||||
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
|
@ -20,7 +25,7 @@ from homeassistant.helpers.selector import (
|
|||
SelectSelectorMode,
|
||||
)
|
||||
|
||||
from .const import CONF_COUNTRY_CODE, DOMAIN
|
||||
from .const import DOMAIN
|
||||
from .helpers import fetch_latest_carbon_intensity
|
||||
from .util import get_extra_name
|
||||
|
||||
|
|
|
@ -2,5 +2,4 @@
|
|||
|
||||
|
||||
DOMAIN = "co2signal"
|
||||
CONF_COUNTRY_CODE = "country_code"
|
||||
ATTRIBUTION = "Data provided by Electricity Maps"
|
||||
|
|
|
@ -5,11 +5,9 @@ from typing import Any
|
|||
from aioelectricitymaps import ElectricityMaps
|
||||
from aioelectricitymaps.models import CarbonIntensityResponse
|
||||
|
||||
from homeassistant.const import CONF_LATITUDE, CONF_LONGITUDE
|
||||
from homeassistant.const import CONF_COUNTRY_CODE, CONF_LATITUDE, CONF_LONGITUDE
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
from .const import CONF_COUNTRY_CODE
|
||||
|
||||
|
||||
async def fetch_latest_carbon_intensity(
|
||||
hass: HomeAssistant,
|
||||
|
|
|
@ -3,9 +3,7 @@ from __future__ import annotations
|
|||
|
||||
from collections.abc import Mapping
|
||||
|
||||
from homeassistant.const import CONF_LATITUDE, CONF_LONGITUDE
|
||||
|
||||
from .const import CONF_COUNTRY_CODE
|
||||
from homeassistant.const import CONF_COUNTRY_CODE, CONF_LATITUDE, CONF_LONGITUDE
|
||||
|
||||
|
||||
def get_extra_name(config: Mapping) -> str | None:
|
||||
|
|
|
@ -3,10 +3,10 @@
|
|||
from python_picnic_api import PicnicAPI
|
||||
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import CONF_ACCESS_TOKEN, Platform
|
||||
from homeassistant.const import CONF_ACCESS_TOKEN, CONF_COUNTRY_CODE, Platform
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
from .const import CONF_API, CONF_COORDINATOR, CONF_COUNTRY_CODE, DOMAIN
|
||||
from .const import CONF_API, CONF_COORDINATOR, DOMAIN
|
||||
from .coordinator import PicnicUpdateCoordinator
|
||||
from .services import async_register_services
|
||||
|
||||
|
|
|
@ -12,10 +12,15 @@ import voluptuous as vol
|
|||
|
||||
from homeassistant import config_entries, core, exceptions
|
||||
from homeassistant.config_entries import SOURCE_REAUTH
|
||||
from homeassistant.const import CONF_ACCESS_TOKEN, CONF_PASSWORD, CONF_USERNAME
|
||||
from homeassistant.const import (
|
||||
CONF_ACCESS_TOKEN,
|
||||
CONF_COUNTRY_CODE,
|
||||
CONF_PASSWORD,
|
||||
CONF_USERNAME,
|
||||
)
|
||||
from homeassistant.data_entry_flow import FlowResult
|
||||
|
||||
from .const import CONF_COUNTRY_CODE, COUNTRY_CODES, DOMAIN
|
||||
from .const import COUNTRY_CODES, DOMAIN
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
|
|
@ -5,7 +5,6 @@ DOMAIN = "picnic"
|
|||
|
||||
CONF_API = "api"
|
||||
CONF_COORDINATOR = "coordinator"
|
||||
CONF_COUNTRY_CODE = "country_code"
|
||||
|
||||
SERVICE_ADD_PRODUCT_TO_CART = "add_product"
|
||||
|
||||
|
|
|
@ -15,6 +15,7 @@ from tuya_iot import (
|
|||
)
|
||||
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import CONF_COUNTRY_CODE
|
||||
from homeassistant.core import HomeAssistant, callback
|
||||
from homeassistant.exceptions import ConfigEntryNotReady
|
||||
from homeassistant.helpers import device_registry as dr
|
||||
|
@ -25,7 +26,6 @@ from .const import (
|
|||
CONF_ACCESS_SECRET,
|
||||
CONF_APP_TYPE,
|
||||
CONF_AUTH_TYPE,
|
||||
CONF_COUNTRY_CODE,
|
||||
CONF_ENDPOINT,
|
||||
CONF_PASSWORD,
|
||||
CONF_USERNAME,
|
||||
|
|
|
@ -7,13 +7,13 @@ from tuya_iot import AuthType, TuyaOpenAPI
|
|||
import voluptuous as vol
|
||||
|
||||
from homeassistant import config_entries
|
||||
from homeassistant.const import CONF_COUNTRY_CODE
|
||||
|
||||
from .const import (
|
||||
CONF_ACCESS_ID,
|
||||
CONF_ACCESS_SECRET,
|
||||
CONF_APP_TYPE,
|
||||
CONF_AUTH_TYPE,
|
||||
CONF_COUNTRY_CODE,
|
||||
CONF_ENDPOINT,
|
||||
CONF_PASSWORD,
|
||||
CONF_USERNAME,
|
||||
|
|
|
@ -38,7 +38,6 @@ CONF_ACCESS_ID = "access_id"
|
|||
CONF_ACCESS_SECRET = "access_secret"
|
||||
CONF_USERNAME = "username"
|
||||
CONF_PASSWORD = "password"
|
||||
CONF_COUNTRY_CODE = "country_code"
|
||||
CONF_APP_TYPE = "tuya_app_type"
|
||||
|
||||
TUYA_DISCOVERY_NEW = "tuya_discovery_new"
|
||||
|
|
|
@ -9,20 +9,14 @@ from tuya_iot import TuyaDevice
|
|||
|
||||
from homeassistant.components.diagnostics import REDACTED
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import CONF_COUNTRY_CODE
|
||||
from homeassistant.core import HomeAssistant, callback
|
||||
from homeassistant.helpers import device_registry as dr, entity_registry as er
|
||||
from homeassistant.helpers.device_registry import DeviceEntry
|
||||
from homeassistant.util import dt as dt_util
|
||||
|
||||
from . import HomeAssistantTuyaData
|
||||
from .const import (
|
||||
CONF_APP_TYPE,
|
||||
CONF_AUTH_TYPE,
|
||||
CONF_COUNTRY_CODE,
|
||||
CONF_ENDPOINT,
|
||||
DOMAIN,
|
||||
DPCode,
|
||||
)
|
||||
from .const import CONF_APP_TYPE, CONF_AUTH_TYPE, CONF_ENDPOINT, DOMAIN, DPCode
|
||||
|
||||
|
||||
async def async_get_config_entry_diagnostics(
|
||||
|
|
|
@ -129,6 +129,7 @@ CONF_CONTINUE_ON_ERROR: Final = "continue_on_error"
|
|||
CONF_CONTINUE_ON_TIMEOUT: Final = "continue_on_timeout"
|
||||
CONF_COUNT: Final = "count"
|
||||
CONF_COUNTRY: Final = "country"
|
||||
CONF_COUNTRY_CODE: Final = "country_code"
|
||||
CONF_COVERS: Final = "covers"
|
||||
CONF_CURRENCY: Final = "currency"
|
||||
CONF_CUSTOMIZE: Final = "customize"
|
||||
|
|
|
@ -6,8 +6,8 @@ from http import HTTPStatus
|
|||
|
||||
from aiohttp.client_exceptions import ClientResponseError
|
||||
|
||||
from homeassistant.components.buienradar.const import CONF_COUNTRY, CONF_DELTA, DOMAIN
|
||||
from homeassistant.const import CONF_LATITUDE, CONF_LONGITUDE
|
||||
from homeassistant.components.buienradar.const import CONF_DELTA, DOMAIN
|
||||
from homeassistant.const import CONF_COUNTRY_CODE, CONF_LATITUDE, CONF_LONGITUDE
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.entity_registry import async_get
|
||||
from homeassistant.util import dt as dt_util
|
||||
|
@ -144,7 +144,7 @@ async def test_belgium_country(
|
|||
aioclient_mock.get(radar_map_url(country_code="BE"), text="hello world")
|
||||
|
||||
data = copy.deepcopy(TEST_CFG_DATA)
|
||||
data[CONF_COUNTRY] = "BE"
|
||||
data[CONF_COUNTRY_CODE] = "BE"
|
||||
|
||||
mock_entry = MockConfigEntry(domain=DOMAIN, unique_id="TEST_ID", data=data)
|
||||
|
||||
|
|
|
@ -6,8 +6,8 @@ from python_picnic_api.session import PicnicAuthError
|
|||
import requests
|
||||
|
||||
from homeassistant import config_entries, data_entry_flow
|
||||
from homeassistant.components.picnic.const import CONF_COUNTRY_CODE, DOMAIN
|
||||
from homeassistant.const import CONF_ACCESS_TOKEN
|
||||
from homeassistant.components.picnic.const import DOMAIN
|
||||
from homeassistant.const import CONF_ACCESS_TOKEN, CONF_COUNTRY_CODE
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
from tests.common import MockConfigEntry
|
||||
|
|
|
@ -9,11 +9,12 @@ import requests
|
|||
|
||||
from homeassistant import config_entries
|
||||
from homeassistant.components.picnic import const
|
||||
from homeassistant.components.picnic.const import CONF_COUNTRY_CODE, DOMAIN
|
||||
from homeassistant.components.picnic.const import DOMAIN
|
||||
from homeassistant.components.picnic.sensor import SENSOR_TYPES
|
||||
from homeassistant.components.sensor import SensorDeviceClass
|
||||
from homeassistant.const import (
|
||||
CONF_ACCESS_TOKEN,
|
||||
CONF_COUNTRY_CODE,
|
||||
CURRENCY_EURO,
|
||||
STATE_UNAVAILABLE,
|
||||
STATE_UNKNOWN,
|
||||
|
|
|
@ -13,7 +13,6 @@ from homeassistant.components.tuya.const import (
|
|||
CONF_ACCESS_SECRET,
|
||||
CONF_APP_TYPE,
|
||||
CONF_AUTH_TYPE,
|
||||
CONF_COUNTRY_CODE,
|
||||
CONF_ENDPOINT,
|
||||
CONF_PASSWORD,
|
||||
CONF_USERNAME,
|
||||
|
@ -22,6 +21,7 @@ from homeassistant.components.tuya.const import (
|
|||
TUYA_COUNTRIES,
|
||||
TUYA_SMART_APP,
|
||||
)
|
||||
from homeassistant.const import CONF_COUNTRY_CODE
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
MOCK_SMART_HOME_PROJECT_TYPE = 0
|
||||
|
|
Loading…
Add table
Reference in a new issue