mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 05:07:41 +00:00
Add support for imperial units of measure in volvooncall (#77669)
This commit is contained in:
parent
acf8bfb299
commit
691df5a394
@ -15,6 +15,7 @@ from homeassistant.const import (
|
|||||||
CONF_REGION,
|
CONF_REGION,
|
||||||
CONF_RESOURCES,
|
CONF_RESOURCES,
|
||||||
CONF_SCAN_INTERVAL,
|
CONF_SCAN_INTERVAL,
|
||||||
|
CONF_UNIT_SYSTEM,
|
||||||
CONF_USERNAME,
|
CONF_USERNAME,
|
||||||
)
|
)
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
@ -38,6 +39,9 @@ from .const import (
|
|||||||
DOMAIN,
|
DOMAIN,
|
||||||
PLATFORMS,
|
PLATFORMS,
|
||||||
RESOURCES,
|
RESOURCES,
|
||||||
|
UNIT_SYSTEM_IMPERIAL,
|
||||||
|
UNIT_SYSTEM_METRIC,
|
||||||
|
UNIT_SYSTEM_SCANDINAVIAN_MILES,
|
||||||
VOLVO_DISCOVERY_NEW,
|
VOLVO_DISCOVERY_NEW,
|
||||||
)
|
)
|
||||||
from .errors import InvalidAuth
|
from .errors import InvalidAuth
|
||||||
@ -109,6 +113,19 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
|||||||
|
|
||||||
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||||
"""Set up the Volvo On Call component from a ConfigEntry."""
|
"""Set up the Volvo On Call component from a ConfigEntry."""
|
||||||
|
|
||||||
|
# added CONF_UNIT_SYSTEM / deprecated CONF_SCANDINAVIAN_MILES in 2022.10 to support imperial units
|
||||||
|
if CONF_UNIT_SYSTEM not in entry.data:
|
||||||
|
new_conf = {**entry.data}
|
||||||
|
|
||||||
|
scandinavian_miles: bool = entry.data[CONF_SCANDINAVIAN_MILES]
|
||||||
|
|
||||||
|
new_conf[CONF_UNIT_SYSTEM] = (
|
||||||
|
UNIT_SYSTEM_SCANDINAVIAN_MILES if scandinavian_miles else UNIT_SYSTEM_METRIC
|
||||||
|
)
|
||||||
|
|
||||||
|
hass.config_entries.async_update_entry(entry, data=new_conf)
|
||||||
|
|
||||||
session = async_get_clientsession(hass)
|
session = async_get_clientsession(hass)
|
||||||
|
|
||||||
connection = Connection(
|
connection = Connection(
|
||||||
@ -183,7 +200,13 @@ class VolvoData:
|
|||||||
|
|
||||||
dashboard = vehicle.dashboard(
|
dashboard = vehicle.dashboard(
|
||||||
mutable=self.config_entry.data[CONF_MUTABLE],
|
mutable=self.config_entry.data[CONF_MUTABLE],
|
||||||
scandinavian_miles=self.config_entry.data[CONF_SCANDINAVIAN_MILES],
|
scandinavian_miles=(
|
||||||
|
self.config_entry.data[CONF_UNIT_SYSTEM]
|
||||||
|
== UNIT_SYSTEM_SCANDINAVIAN_MILES
|
||||||
|
),
|
||||||
|
usa_units=(
|
||||||
|
self.config_entry.data[CONF_UNIT_SYSTEM] == UNIT_SYSTEM_IMPERIAL
|
||||||
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
for instrument in (
|
for instrument in (
|
||||||
|
@ -9,12 +9,23 @@ import voluptuous as vol
|
|||||||
from volvooncall import Connection
|
from volvooncall import Connection
|
||||||
|
|
||||||
from homeassistant import config_entries
|
from homeassistant import config_entries
|
||||||
from homeassistant.const import CONF_PASSWORD, CONF_REGION, CONF_USERNAME
|
from homeassistant.const import (
|
||||||
|
CONF_PASSWORD,
|
||||||
|
CONF_REGION,
|
||||||
|
CONF_UNIT_SYSTEM,
|
||||||
|
CONF_USERNAME,
|
||||||
|
)
|
||||||
from homeassistant.data_entry_flow import FlowResult
|
from homeassistant.data_entry_flow import FlowResult
|
||||||
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
||||||
|
|
||||||
from . import VolvoData
|
from . import VolvoData
|
||||||
from .const import CONF_MUTABLE, CONF_SCANDINAVIAN_MILES, DOMAIN
|
from .const import (
|
||||||
|
CONF_MUTABLE,
|
||||||
|
DOMAIN,
|
||||||
|
UNIT_SYSTEM_IMPERIAL,
|
||||||
|
UNIT_SYSTEM_METRIC,
|
||||||
|
UNIT_SYSTEM_SCANDINAVIAN_MILES,
|
||||||
|
)
|
||||||
from .errors import InvalidAuth
|
from .errors import InvalidAuth
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
@ -36,7 +47,7 @@ class VolvoOnCallConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
|||||||
CONF_PASSWORD: "",
|
CONF_PASSWORD: "",
|
||||||
CONF_REGION: None,
|
CONF_REGION: None,
|
||||||
CONF_MUTABLE: True,
|
CONF_MUTABLE: True,
|
||||||
CONF_SCANDINAVIAN_MILES: False,
|
CONF_UNIT_SYSTEM: UNIT_SYSTEM_METRIC,
|
||||||
}
|
}
|
||||||
|
|
||||||
if user_input is not None:
|
if user_input is not None:
|
||||||
@ -76,10 +87,16 @@ class VolvoOnCallConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
|||||||
vol.Required(CONF_REGION, default=defaults[CONF_REGION]): vol.In(
|
vol.Required(CONF_REGION, default=defaults[CONF_REGION]): vol.In(
|
||||||
{"na": "North America", "cn": "China", None: "Rest of world"}
|
{"na": "North America", "cn": "China", None: "Rest of world"}
|
||||||
),
|
),
|
||||||
vol.Optional(CONF_MUTABLE, default=defaults[CONF_MUTABLE]): bool,
|
|
||||||
vol.Optional(
|
vol.Optional(
|
||||||
CONF_SCANDINAVIAN_MILES, default=defaults[CONF_SCANDINAVIAN_MILES]
|
CONF_UNIT_SYSTEM, default=defaults[CONF_UNIT_SYSTEM]
|
||||||
): bool,
|
): vol.In(
|
||||||
|
{
|
||||||
|
UNIT_SYSTEM_METRIC: "Metric",
|
||||||
|
UNIT_SYSTEM_SCANDINAVIAN_MILES: "Metric with Scandinavian Miles",
|
||||||
|
UNIT_SYSTEM_IMPERIAL: "Imperial",
|
||||||
|
}
|
||||||
|
),
|
||||||
|
vol.Optional(CONF_MUTABLE, default=defaults[CONF_MUTABLE]): bool,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -10,6 +10,10 @@ CONF_SERVICE_URL = "service_url"
|
|||||||
CONF_SCANDINAVIAN_MILES = "scandinavian_miles"
|
CONF_SCANDINAVIAN_MILES = "scandinavian_miles"
|
||||||
CONF_MUTABLE = "mutable"
|
CONF_MUTABLE = "mutable"
|
||||||
|
|
||||||
|
UNIT_SYSTEM_SCANDINAVIAN_MILES = "scandinavian_miles"
|
||||||
|
UNIT_SYSTEM_METRIC = "metric"
|
||||||
|
UNIT_SYSTEM_IMPERIAL = "imperial"
|
||||||
|
|
||||||
PLATFORMS = {
|
PLATFORMS = {
|
||||||
"sensor": "sensor",
|
"sensor": "sensor",
|
||||||
"binary_sensor": "binary_sensor",
|
"binary_sensor": "binary_sensor",
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
"domain": "volvooncall",
|
"domain": "volvooncall",
|
||||||
"name": "Volvo On Call",
|
"name": "Volvo On Call",
|
||||||
"documentation": "https://www.home-assistant.io/integrations/volvooncall",
|
"documentation": "https://www.home-assistant.io/integrations/volvooncall",
|
||||||
"requirements": ["volvooncall==0.10.0"],
|
"requirements": ["volvooncall==0.10.1"],
|
||||||
"codeowners": ["@molobrakos"],
|
"codeowners": ["@molobrakos"],
|
||||||
"iot_class": "cloud_polling",
|
"iot_class": "cloud_polling",
|
||||||
"loggers": ["geopy", "hbmqtt", "volvooncall"],
|
"loggers": ["geopy", "hbmqtt", "volvooncall"],
|
||||||
|
@ -6,8 +6,8 @@
|
|||||||
"username": "[%key:common::config_flow::data::username%]",
|
"username": "[%key:common::config_flow::data::username%]",
|
||||||
"password": "[%key:common::config_flow::data::password%]",
|
"password": "[%key:common::config_flow::data::password%]",
|
||||||
"region": "Region",
|
"region": "Region",
|
||||||
"mutable": "Allow Remote Start / Lock / etc.",
|
"unit_system": "Unit System",
|
||||||
"scandinavian_miles": "Use Scandinavian Miles"
|
"mutable": "Allow Remote Start / Lock / etc."
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -1,29 +1,29 @@
|
|||||||
{
|
{
|
||||||
"config": {
|
"config": {
|
||||||
"abort": {
|
"step": {
|
||||||
"already_configured": "Account is already configured",
|
"user": {
|
||||||
"reauth_successful": "Re-authentication was successful"
|
"data": {
|
||||||
|
"username": "Username",
|
||||||
|
"password": "Password",
|
||||||
|
"region": "Region",
|
||||||
|
"mutable": "Allow Remote Start / Lock / etc.",
|
||||||
|
"unit_system": "Unit System"
|
||||||
|
}
|
||||||
|
}
|
||||||
},
|
},
|
||||||
"error": {
|
"error": {
|
||||||
"invalid_auth": "Invalid authentication",
|
"invalid_auth": "Invalid authentication",
|
||||||
"unknown": "Unexpected error"
|
"unknown": "Unexpected error"
|
||||||
},
|
},
|
||||||
"step": {
|
"abort": {
|
||||||
"user": {
|
"already_configured": "Account is already configured",
|
||||||
"data": {
|
"reauth_successful": "Re-authentication was successful"
|
||||||
"mutable": "Allow Remote Start / Lock / etc.",
|
|
||||||
"password": "Password",
|
|
||||||
"region": "Region",
|
|
||||||
"scandinavian_miles": "Use Scandinavian Miles",
|
|
||||||
"username": "Username"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"issues": {
|
"issues": {
|
||||||
"deprecated_yaml": {
|
"deprecated_yaml": {
|
||||||
"description": "Configuring the Volvo On Call platform using YAML is being removed in a future release of Home Assistant.\n\nYour existing configuration has been imported into the UI automatically. Remove the YAML configuration from your configuration.yaml file and restart Home Assistant to fix this issue.",
|
"title": "The Volvo On Call YAML configuration is being removed",
|
||||||
"title": "The Volvo On Call YAML configuration is being removed"
|
"description": "Configuring the Volvo On Call platform using YAML is being removed in a future release of Home Assistant.\n\nYour existing configuration has been imported into the UI automatically. Remove the YAML configuration from your configuration.yaml file and restart Home Assistant to fix this issue."
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -2473,7 +2473,7 @@ vilfo-api-client==0.3.2
|
|||||||
volkszaehler==0.3.2
|
volkszaehler==0.3.2
|
||||||
|
|
||||||
# homeassistant.components.volvooncall
|
# homeassistant.components.volvooncall
|
||||||
volvooncall==0.10.0
|
volvooncall==0.10.1
|
||||||
|
|
||||||
# homeassistant.components.verisure
|
# homeassistant.components.verisure
|
||||||
vsure==1.8.1
|
vsure==1.8.1
|
||||||
|
@ -1698,7 +1698,7 @@ venstarcolortouch==0.18
|
|||||||
vilfo-api-client==0.3.2
|
vilfo-api-client==0.3.2
|
||||||
|
|
||||||
# homeassistant.components.volvooncall
|
# homeassistant.components.volvooncall
|
||||||
volvooncall==0.10.0
|
volvooncall==0.10.1
|
||||||
|
|
||||||
# homeassistant.components.verisure
|
# homeassistant.components.verisure
|
||||||
vsure==1.8.1
|
vsure==1.8.1
|
||||||
|
@ -29,8 +29,8 @@ async def test_form(hass: HomeAssistant) -> None:
|
|||||||
"username": "test-username",
|
"username": "test-username",
|
||||||
"password": "test-password",
|
"password": "test-password",
|
||||||
"region": "na",
|
"region": "na",
|
||||||
|
"unit_system": "metric",
|
||||||
"mutable": True,
|
"mutable": True,
|
||||||
"scandinavian_miles": False,
|
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
@ -41,8 +41,8 @@ async def test_form(hass: HomeAssistant) -> None:
|
|||||||
"username": "test-username",
|
"username": "test-username",
|
||||||
"password": "test-password",
|
"password": "test-password",
|
||||||
"region": "na",
|
"region": "na",
|
||||||
|
"unit_system": "metric",
|
||||||
"mutable": True,
|
"mutable": True,
|
||||||
"scandinavian_miles": False,
|
|
||||||
}
|
}
|
||||||
assert len(mock_setup_entry.mock_calls) == 1
|
assert len(mock_setup_entry.mock_calls) == 1
|
||||||
|
|
||||||
@ -65,8 +65,8 @@ async def test_form_invalid_auth(hass: HomeAssistant) -> None:
|
|||||||
"username": "test-username",
|
"username": "test-username",
|
||||||
"password": "test-password",
|
"password": "test-password",
|
||||||
"region": "na",
|
"region": "na",
|
||||||
|
"unit_system": "metric",
|
||||||
"mutable": True,
|
"mutable": True,
|
||||||
"scandinavian_miles": False,
|
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -95,8 +95,8 @@ async def test_flow_already_configured(hass: HomeAssistant) -> None:
|
|||||||
"username": "test-username",
|
"username": "test-username",
|
||||||
"password": "test-password",
|
"password": "test-password",
|
||||||
"region": "na",
|
"region": "na",
|
||||||
|
"unit_system": "metric",
|
||||||
"mutable": True,
|
"mutable": True,
|
||||||
"scandinavian_miles": False,
|
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
@ -121,8 +121,8 @@ async def test_form_other_exception(hass: HomeAssistant) -> None:
|
|||||||
"username": "test-username",
|
"username": "test-username",
|
||||||
"password": "test-password",
|
"password": "test-password",
|
||||||
"region": "na",
|
"region": "na",
|
||||||
|
"unit_system": "metric",
|
||||||
"mutable": True,
|
"mutable": True,
|
||||||
"scandinavian_miles": False,
|
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -151,8 +151,8 @@ async def test_import(hass: HomeAssistant) -> None:
|
|||||||
"username": "test-username",
|
"username": "test-username",
|
||||||
"password": "test-password",
|
"password": "test-password",
|
||||||
"region": "na",
|
"region": "na",
|
||||||
|
"unit_system": "metric",
|
||||||
"mutable": True,
|
"mutable": True,
|
||||||
"scandinavian_miles": False,
|
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
@ -163,8 +163,8 @@ async def test_import(hass: HomeAssistant) -> None:
|
|||||||
"username": "test-username",
|
"username": "test-username",
|
||||||
"password": "test-password",
|
"password": "test-password",
|
||||||
"region": "na",
|
"region": "na",
|
||||||
|
"unit_system": "metric",
|
||||||
"mutable": True,
|
"mutable": True,
|
||||||
"scandinavian_miles": False,
|
|
||||||
}
|
}
|
||||||
assert len(mock_setup_entry.mock_calls) == 1
|
assert len(mock_setup_entry.mock_calls) == 1
|
||||||
|
|
||||||
@ -179,8 +179,8 @@ async def test_reauth(hass: HomeAssistant) -> None:
|
|||||||
"username": "test-username",
|
"username": "test-username",
|
||||||
"password": "test-password",
|
"password": "test-password",
|
||||||
"region": "na",
|
"region": "na",
|
||||||
|
"unit_system": "metric",
|
||||||
"mutable": True,
|
"mutable": True,
|
||||||
"scandinavian_miles": False,
|
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
first_entry.add_to_hass(hass)
|
first_entry.add_to_hass(hass)
|
||||||
@ -212,8 +212,8 @@ async def test_reauth(hass: HomeAssistant) -> None:
|
|||||||
"username": "test-username",
|
"username": "test-username",
|
||||||
"password": "test-new-password",
|
"password": "test-new-password",
|
||||||
"region": "na",
|
"region": "na",
|
||||||
|
"unit_system": "metric",
|
||||||
"mutable": True,
|
"mutable": True,
|
||||||
"scandinavian_miles": False,
|
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user