Add support for imperial units of measure in volvooncall (#77669)
This commit is contained in:
parent
acf8bfb299
commit
691df5a394
9 changed files with 81 additions and 37 deletions
|
@ -15,6 +15,7 @@ from homeassistant.const import (
|
|||
CONF_REGION,
|
||||
CONF_RESOURCES,
|
||||
CONF_SCAN_INTERVAL,
|
||||
CONF_UNIT_SYSTEM,
|
||||
CONF_USERNAME,
|
||||
)
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
@ -38,6 +39,9 @@ from .const import (
|
|||
DOMAIN,
|
||||
PLATFORMS,
|
||||
RESOURCES,
|
||||
UNIT_SYSTEM_IMPERIAL,
|
||||
UNIT_SYSTEM_METRIC,
|
||||
UNIT_SYSTEM_SCANDINAVIAN_MILES,
|
||||
VOLVO_DISCOVERY_NEW,
|
||||
)
|
||||
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:
|
||||
"""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)
|
||||
|
||||
connection = Connection(
|
||||
|
@ -183,7 +200,13 @@ class VolvoData:
|
|||
|
||||
dashboard = vehicle.dashboard(
|
||||
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 (
|
||||
|
|
|
@ -9,12 +9,23 @@ import voluptuous as vol
|
|||
from volvooncall import Connection
|
||||
|
||||
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.helpers.aiohttp_client import async_get_clientsession
|
||||
|
||||
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
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
@ -36,7 +47,7 @@ class VolvoOnCallConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
|||
CONF_PASSWORD: "",
|
||||
CONF_REGION: None,
|
||||
CONF_MUTABLE: True,
|
||||
CONF_SCANDINAVIAN_MILES: False,
|
||||
CONF_UNIT_SYSTEM: UNIT_SYSTEM_METRIC,
|
||||
}
|
||||
|
||||
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(
|
||||
{"na": "North America", "cn": "China", None: "Rest of world"}
|
||||
),
|
||||
vol.Optional(CONF_MUTABLE, default=defaults[CONF_MUTABLE]): bool,
|
||||
vol.Optional(
|
||||
CONF_SCANDINAVIAN_MILES, default=defaults[CONF_SCANDINAVIAN_MILES]
|
||||
): bool,
|
||||
CONF_UNIT_SYSTEM, default=defaults[CONF_UNIT_SYSTEM]
|
||||
): 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_MUTABLE = "mutable"
|
||||
|
||||
UNIT_SYSTEM_SCANDINAVIAN_MILES = "scandinavian_miles"
|
||||
UNIT_SYSTEM_METRIC = "metric"
|
||||
UNIT_SYSTEM_IMPERIAL = "imperial"
|
||||
|
||||
PLATFORMS = {
|
||||
"sensor": "sensor",
|
||||
"binary_sensor": "binary_sensor",
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
"domain": "volvooncall",
|
||||
"name": "Volvo On Call",
|
||||
"documentation": "https://www.home-assistant.io/integrations/volvooncall",
|
||||
"requirements": ["volvooncall==0.10.0"],
|
||||
"requirements": ["volvooncall==0.10.1"],
|
||||
"codeowners": ["@molobrakos"],
|
||||
"iot_class": "cloud_polling",
|
||||
"loggers": ["geopy", "hbmqtt", "volvooncall"],
|
||||
|
|
|
@ -6,8 +6,8 @@
|
|||
"username": "[%key:common::config_flow::data::username%]",
|
||||
"password": "[%key:common::config_flow::data::password%]",
|
||||
"region": "Region",
|
||||
"mutable": "Allow Remote Start / Lock / etc.",
|
||||
"scandinavian_miles": "Use Scandinavian Miles"
|
||||
"unit_system": "Unit System",
|
||||
"mutable": "Allow Remote Start / Lock / etc."
|
||||
}
|
||||
}
|
||||
},
|
||||
|
|
|
@ -1,29 +1,29 @@
|
|||
{
|
||||
"config": {
|
||||
"abort": {
|
||||
"already_configured": "Account is already configured",
|
||||
"reauth_successful": "Re-authentication was successful"
|
||||
"step": {
|
||||
"user": {
|
||||
"data": {
|
||||
"username": "Username",
|
||||
"password": "Password",
|
||||
"region": "Region",
|
||||
"mutable": "Allow Remote Start / Lock / etc.",
|
||||
"unit_system": "Unit System"
|
||||
}
|
||||
}
|
||||
},
|
||||
"error": {
|
||||
"invalid_auth": "Invalid authentication",
|
||||
"unknown": "Unexpected error"
|
||||
},
|
||||
"step": {
|
||||
"user": {
|
||||
"data": {
|
||||
"mutable": "Allow Remote Start / Lock / etc.",
|
||||
"password": "Password",
|
||||
"region": "Region",
|
||||
"scandinavian_miles": "Use Scandinavian Miles",
|
||||
"username": "Username"
|
||||
}
|
||||
}
|
||||
"abort": {
|
||||
"already_configured": "Account is already configured",
|
||||
"reauth_successful": "Re-authentication was successful"
|
||||
}
|
||||
},
|
||||
"issues": {
|
||||
"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
|
||||
|
||||
# homeassistant.components.volvooncall
|
||||
volvooncall==0.10.0
|
||||
volvooncall==0.10.1
|
||||
|
||||
# homeassistant.components.verisure
|
||||
vsure==1.8.1
|
||||
|
|
|
@ -1698,7 +1698,7 @@ venstarcolortouch==0.18
|
|||
vilfo-api-client==0.3.2
|
||||
|
||||
# homeassistant.components.volvooncall
|
||||
volvooncall==0.10.0
|
||||
volvooncall==0.10.1
|
||||
|
||||
# homeassistant.components.verisure
|
||||
vsure==1.8.1
|
||||
|
|
|
@ -29,8 +29,8 @@ async def test_form(hass: HomeAssistant) -> None:
|
|||
"username": "test-username",
|
||||
"password": "test-password",
|
||||
"region": "na",
|
||||
"unit_system": "metric",
|
||||
"mutable": True,
|
||||
"scandinavian_miles": False,
|
||||
},
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
@ -41,8 +41,8 @@ async def test_form(hass: HomeAssistant) -> None:
|
|||
"username": "test-username",
|
||||
"password": "test-password",
|
||||
"region": "na",
|
||||
"unit_system": "metric",
|
||||
"mutable": True,
|
||||
"scandinavian_miles": False,
|
||||
}
|
||||
assert len(mock_setup_entry.mock_calls) == 1
|
||||
|
||||
|
@ -65,8 +65,8 @@ async def test_form_invalid_auth(hass: HomeAssistant) -> None:
|
|||
"username": "test-username",
|
||||
"password": "test-password",
|
||||
"region": "na",
|
||||
"unit_system": "metric",
|
||||
"mutable": True,
|
||||
"scandinavian_miles": False,
|
||||
},
|
||||
)
|
||||
|
||||
|
@ -95,8 +95,8 @@ async def test_flow_already_configured(hass: HomeAssistant) -> None:
|
|||
"username": "test-username",
|
||||
"password": "test-password",
|
||||
"region": "na",
|
||||
"unit_system": "metric",
|
||||
"mutable": True,
|
||||
"scandinavian_miles": False,
|
||||
},
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
@ -121,8 +121,8 @@ async def test_form_other_exception(hass: HomeAssistant) -> None:
|
|||
"username": "test-username",
|
||||
"password": "test-password",
|
||||
"region": "na",
|
||||
"unit_system": "metric",
|
||||
"mutable": True,
|
||||
"scandinavian_miles": False,
|
||||
},
|
||||
)
|
||||
|
||||
|
@ -151,8 +151,8 @@ async def test_import(hass: HomeAssistant) -> None:
|
|||
"username": "test-username",
|
||||
"password": "test-password",
|
||||
"region": "na",
|
||||
"unit_system": "metric",
|
||||
"mutable": True,
|
||||
"scandinavian_miles": False,
|
||||
},
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
@ -163,8 +163,8 @@ async def test_import(hass: HomeAssistant) -> None:
|
|||
"username": "test-username",
|
||||
"password": "test-password",
|
||||
"region": "na",
|
||||
"unit_system": "metric",
|
||||
"mutable": True,
|
||||
"scandinavian_miles": False,
|
||||
}
|
||||
assert len(mock_setup_entry.mock_calls) == 1
|
||||
|
||||
|
@ -179,8 +179,8 @@ async def test_reauth(hass: HomeAssistant) -> None:
|
|||
"username": "test-username",
|
||||
"password": "test-password",
|
||||
"region": "na",
|
||||
"unit_system": "metric",
|
||||
"mutable": True,
|
||||
"scandinavian_miles": False,
|
||||
},
|
||||
)
|
||||
first_entry.add_to_hass(hass)
|
||||
|
@ -212,8 +212,8 @@ async def test_reauth(hass: HomeAssistant) -> None:
|
|||
"username": "test-username",
|
||||
"password": "test-new-password",
|
||||
"region": "na",
|
||||
"unit_system": "metric",
|
||||
"mutable": True,
|
||||
"scandinavian_miles": False,
|
||||
},
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
|
Loading…
Add table
Reference in a new issue