From 691df5a394aa4ebd4e67fbd2ce74f26ab5abcc3f Mon Sep 17 00:00:00 2001 From: y34hbuddy <47507530+y34hbuddy@users.noreply.github.com> Date: Mon, 19 Sep 2022 10:22:13 -0400 Subject: [PATCH] Add support for imperial units of measure in volvooncall (#77669) --- .../components/volvooncall/__init__.py | 25 ++++++++++++++- .../components/volvooncall/config_flow.py | 29 +++++++++++++---- homeassistant/components/volvooncall/const.py | 4 +++ .../components/volvooncall/manifest.json | 2 +- .../components/volvooncall/strings.json | 4 +-- .../volvooncall/translations/en.json | 32 +++++++++---------- requirements_all.txt | 2 +- requirements_test_all.txt | 2 +- .../volvooncall/test_config_flow.py | 18 +++++------ 9 files changed, 81 insertions(+), 37 deletions(-) diff --git a/homeassistant/components/volvooncall/__init__.py b/homeassistant/components/volvooncall/__init__.py index 65e3b4b0c4e..5a24712b7a3 100644 --- a/homeassistant/components/volvooncall/__init__.py +++ b/homeassistant/components/volvooncall/__init__.py @@ -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 ( diff --git a/homeassistant/components/volvooncall/config_flow.py b/homeassistant/components/volvooncall/config_flow.py index 2ed3404ae94..c04fe6b4c4c 100644 --- a/homeassistant/components/volvooncall/config_flow.py +++ b/homeassistant/components/volvooncall/config_flow.py @@ -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, }, ) diff --git a/homeassistant/components/volvooncall/const.py b/homeassistant/components/volvooncall/const.py index bc72f9c5267..4c969669af6 100644 --- a/homeassistant/components/volvooncall/const.py +++ b/homeassistant/components/volvooncall/const.py @@ -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", diff --git a/homeassistant/components/volvooncall/manifest.json b/homeassistant/components/volvooncall/manifest.json index 4865b95d56b..b9da3657aed 100644 --- a/homeassistant/components/volvooncall/manifest.json +++ b/homeassistant/components/volvooncall/manifest.json @@ -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"], diff --git a/homeassistant/components/volvooncall/strings.json b/homeassistant/components/volvooncall/strings.json index a0504094b4d..9e8471b04b1 100644 --- a/homeassistant/components/volvooncall/strings.json +++ b/homeassistant/components/volvooncall/strings.json @@ -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." } } }, diff --git a/homeassistant/components/volvooncall/translations/en.json b/homeassistant/components/volvooncall/translations/en.json index 2b311052741..a75ab687d97 100644 --- a/homeassistant/components/volvooncall/translations/en.json +++ b/homeassistant/components/volvooncall/translations/en.json @@ -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." } } -} \ No newline at end of file +} diff --git a/requirements_all.txt b/requirements_all.txt index 1dc62b18dcb..4032d10e6a0 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -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 diff --git a/requirements_test_all.txt b/requirements_test_all.txt index 8c8517c9080..3679c3b598a 100644 --- a/requirements_test_all.txt +++ b/requirements_test_all.txt @@ -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 diff --git a/tests/components/volvooncall/test_config_flow.py b/tests/components/volvooncall/test_config_flow.py index b558bb7843f..549dc9d4409 100644 --- a/tests/components/volvooncall/test_config_flow.py +++ b/tests/components/volvooncall/test_config_flow.py @@ -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()