Skip to content

Commit

Permalink
Bug fixes (#76 and #79) and minor improvements.
Browse files Browse the repository at this point in the history
  • Loading branch information
Farfar committed Oct 14, 2021
1 parent 7cd3398 commit d7aa1c1
Show file tree
Hide file tree
Showing 11 changed files with 79 additions and 44 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

# Skoda Connect - A Home Assistant custom component for Skoda Connect/MyŠKODA

# v1.0.56
# v1.0.57

## This is fork of [robinostlund/homeassistant-volkswagencarnet](https://github.com/robinostlund/homeassistant-volkswagencarnet) modified to support Skoda Connect/MySkoda through native app API (API calls directly to vwg-connect services)
This integration for Home Assistant will fetch data from Skoda Connect servers related to your Skoda Connect enabled car.
Expand Down
48 changes: 37 additions & 11 deletions custom_components/skodaconnect/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
CONF_NAME,
CONF_PASSWORD,
CONF_RESOURCES,
CONF_SCAN_INTERVAL,
CONF_USERNAME, EVENT_HOMEASSISTANT_STOP,
)
from homeassistant.core import HomeAssistant
Expand Down Expand Up @@ -48,13 +49,12 @@
CONF_SCANDINAVIAN_MILES,
CONF_SPIN,
CONF_VEHICLE,
CONF_UPDATE_INTERVAL,
CONF_INSTRUMENTS,
DATA,
DATA_KEY,
DEFAULT_UPDATE_INTERVAL,
MIN_SCAN_INTERVAL,
DEFAULT_SCAN_INTERVAL,
DOMAIN,
MIN_UPDATE_INTERVAL,
SIGNAL_STATE_UPDATED,
UNDO_UPDATE_LISTENER, UPDATE_CALLBACK, CONF_DEBUG, DEFAULT_DEBUG, CONF_CONVERT, CONF_NO_CONVERSION,
CONF_IMPERIAL_UNITS,
Expand Down Expand Up @@ -130,10 +130,12 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry):
_LOGGER.debug(f'Init async_setup_entry')
hass.data.setdefault(DOMAIN, {})

if entry.options.get(CONF_UPDATE_INTERVAL):
update_interval = timedelta(minutes=entry.options[CONF_UPDATE_INTERVAL])
if entry.options.get(CONF_SCAN_INTERVAL):
update_interval = timedelta(seconds=entry.options[CONF_SCAN_INTERVAL])
else:
update_interval = timedelta(minutes=DEFAULT_UPDATE_INTERVAL)
update_interval = timedelta(seconds=DEFAULT_SCAN_INTERVAL)
if update_interval < timedelta(seconds=MIN_SCAN_INTERVAL):
update_interval = timedelta(seconds=MIN_SCAN_INTERVAL)

coordinator = SkodaCoordinator(hass, entry, update_interval)

Expand Down Expand Up @@ -529,7 +531,28 @@ def get_convert_conf(entry: ConfigEntry):
)
) else CONF_NO_CONVERSION

async def async_migrate_entry(hass: HomeAssistant, entry: ConfigEntry):
"""Migrate configuration from old version to new."""
_LOGGER.debug(f'Migrating from version {entry.version}')

# Migrate data from version 1, pre 1.0.57
if entry.version == 1:
# Make a copy of old config
new = {**entry.data}

# Convert from minutes to seconds for poll interval
minutes = entry.options.get("update_interval", 1)
seconds = minutes*60
new.pop("update_interval", None)
new[CONF_SCAN_INTERVAL] = seconds

# Save "new" config
entry.data = {**new}

entry.version = 2

_LOGGER.info("Migration to version %s successful", entry.version)
return True
class SkodaData:
"""Hold component state."""

Expand Down Expand Up @@ -675,8 +698,11 @@ def device_state_attributes(self):

# Return model image as picture attribute for position entity
if "position" in self.attribute:
if self.vehicle.is_model_image_supported:
attributes["entity_picture"] = self.vehicle.model_image
# Try to use small thumbnail firt hand, else fallback to fullsize
if self.vehicle.is_model_image_small_supported:
attributes["entity_picture"] = self.vehicle.model_image_small
elif self.vehicle.is_model_image_large_supported:
attributes["entity_picture"] = self.vehicle.model_image_large

return attributes

Expand Down Expand Up @@ -779,11 +805,11 @@ async def update(self) -> Union[bool, Vehicle]:
try:
# Get Vehicle object matching VIN number
vehicle = self.connection.vehicle(self.vin)
if not await vehicle.update():
if await vehicle.update():
return vehicle
else:
_LOGGER.warning("Could not query update from Skoda Connect")
return False
else:
return vehicle
except Exception as error:
_LOGGER.warning(f"An error occured while requesting update from Skoda Connect: {error}")
return False
40 changes: 26 additions & 14 deletions custom_components/skodaconnect/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
CONF_PASSWORD,
CONF_RESOURCES,
CONF_USERNAME,
CONF_SCAN_INTERVAL
)
from homeassistant.core import callback
from homeassistant.helpers.aiohttp_client import async_get_clientsession
Expand All @@ -21,19 +22,19 @@
CONF_DEBUG,
CONVERT_DICT,
CONF_MUTABLE,
CONF_UPDATE_INTERVAL,
CONF_SPIN,
CONF_VEHICLE,
CONF_INSTRUMENTS,
DEFAULT_UPDATE_INTERVAL,
MIN_SCAN_INTERVAL,
DEFAULT_SCAN_INTERVAL,
DOMAIN,
DEFAULT_DEBUG
)

_LOGGER = logging.getLogger(__name__)

class SkodaConnectConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
VERSION = 1
VERSION = 2
task_login = None
task_finish = None
task_get_vehicles = None
Expand Down Expand Up @@ -65,7 +66,7 @@ async def async_step_user(self, user_input=None):
self._options = {
CONF_CONVERT: CONF_NO_CONVERSION,
CONF_MUTABLE: True,
CONF_UPDATE_INTERVAL: 5,
CONF_SCAN_INTERVAL: DEFAULT_SCAN_INTERVAL,
CONF_DEBUG: False,
CONF_SPIN: None,
CONF_RESOURCES: []
Expand Down Expand Up @@ -142,7 +143,7 @@ async def async_step_monitoring(self, user_input=None):
if user_input is not None:
self._options[CONF_RESOURCES] = user_input[CONF_RESOURCES]
self._options[CONF_CONVERT] = user_input[CONF_CONVERT]
self._options[CONF_UPDATE_INTERVAL] = user_input[CONF_UPDATE_INTERVAL]
self._options[CONF_SCAN_INTERVAL] = user_input[CONF_SCAN_INTERVAL]
self._options[CONF_DEBUG] = user_input[CONF_DEBUG]

await self.async_set_unique_id(self._data[CONF_VEHICLE])
Expand Down Expand Up @@ -172,8 +173,11 @@ async def async_step_monitoring(self, user_input=None):
CONF_CONVERT, default=CONF_NO_CONVERSION
): vol.In(CONVERT_DICT),
vol.Required(
CONF_UPDATE_INTERVAL, default=1
): cv.positive_int,
CONF_SCAN_INTERVAL, default=DEFAULT_SCAN_INTERVAL
): vol.All(
vol.Coerce(int),
vol.Range(min=MIN_SCAN_INTERVAL, max=900)
),
vol.Required(
CONF_DEBUG, default=False
): cv.boolean
Expand Down Expand Up @@ -300,7 +304,7 @@ async def async_step_import(self, yaml):
self._options = {
CONF_CONVERT: CONF_NO_CONVERSION,
CONF_MUTABLE: True,
CONF_UPDATE_INTERVAL: 5,
CONF_SCAN_INTERVAL: DEFAULT_SCAN_INTERVAL,
CONF_DEBUG: False,
CONF_SPIN: None,
CONF_RESOURCES: []
Expand All @@ -323,8 +327,13 @@ async def async_step_import(self, yaml):
if yaml["scandinavian_miles"]:
self._options[CONF_CONVERT] = "scandinavian_miles"
if "scan_interval" in yaml:
seconds = 60
minutes = 0
if "seconds" in yaml["scan_interval"]:
seconds = int(yaml["scan_interval"]["seconds"])
if "minutes" in yaml["scan_interval"]:
self._options[CONF_UPDATE_INTERVAL] = int(yaml["scan_interval"]["minutes"])
minutes = int(yaml["scan_interval"]["minutes"])
self._options[CONF_SCAN_INTERVAL] = seconds+(minutes*60)
if "name" in yaml:
vin = next(iter(yaml["name"]))
self._data[CONF_VEHICLE] = vin.upper()
Expand Down Expand Up @@ -410,7 +419,7 @@ async def async_step_user(self, user_input=None):
self.hass.config_entries.async_update_entry(self._config_entry, data={**data})

options = self._config_entry.options.copy()
options[CONF_UPDATE_INTERVAL] = user_input.get(CONF_UPDATE_INTERVAL, 1)
options[CONF_SCAN_INTERVAL] = user_input.get(CONF_SCAN_INTERVAL, 1)
options[CONF_SPIN] = user_input.get(CONF_SPIN, None)
options[CONF_MUTABLE] = user_input.get(CONF_MUTABLE, True)
options[CONF_DEBUG] = user_input.get(CONF_DEBUG, False)
Expand Down Expand Up @@ -445,11 +454,14 @@ async def async_step_user(self, user_input=None):
data_schema=vol.Schema(
{
vol.Optional(
CONF_UPDATE_INTERVAL,
default=self._config_entry.options.get(CONF_UPDATE_INTERVAL,
self._config_entry.data.get(CONF_UPDATE_INTERVAL, 5)
CONF_SCAN_INTERVAL,
default=self._config_entry.options.get(CONF_SCAN_INTERVAL,
self._config_entry.data.get(CONF_SCAN_INTERVAL, DEFAULT_SCAN_INTERVAL)
)
): cv.positive_int,
): vol.All(
vol.Coerce(int),
vol.Range(min=MIN_SCAN_INTERVAL, max=900)
),
vol.Optional(
CONF_SPIN,
default=self._config_entry.options.get(CONF_SPIN,
Expand Down
7 changes: 2 additions & 5 deletions custom_components/skodaconnect/const.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from datetime import timedelta

DOMAIN = "skodaconnect"
DATA_KEY = DOMAIN

Expand All @@ -13,7 +11,6 @@
CONF_CONVERT = "convert"
CONF_VEHICLE = "vehicle"
CONF_INSTRUMENTS = "instruments"
CONF_UPDATE_INTERVAL = "update_interval"
CONF_DEBUG = "debug"

# Service definitions
Expand All @@ -29,8 +26,8 @@

SIGNAL_STATE_UPDATED = f"{DOMAIN}.updated"

MIN_UPDATE_INTERVAL = timedelta(minutes=1)
DEFAULT_UPDATE_INTERVAL = 5
MIN_SCAN_INTERVAL = 10
DEFAULT_SCAN_INTERVAL = 60

CONVERT_DICT = {
CONF_NO_CONVERSION: "No conversion",
Expand Down
4 changes: 2 additions & 2 deletions custom_components/skodaconnect/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"@lendik007",
"@Farfar"
],
"requirements": ["skodaconnect>=1.1.6", "homeassistant>=2021.06.0"],
"version": "v1.0.56",
"requirements": ["skodaconnect>=1.1.7", "homeassistant>=2021.06.0"],
"version": "v1.0.57",
"iot_class": "cloud_polling"
}
4 changes: 2 additions & 2 deletions custom_components/skodaconnect/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"data": {
"resources": "Resources to monitor.",
"convert": "Select distance/unit conversions.",
"update_interval": "Poll frequency (minutes).",
"update_interval": "Poll frequency (seconds).",
"debug": "Full API debug logging (requires debug logging enabled in configuration.yaml)"
}
},
Expand Down Expand Up @@ -57,7 +57,7 @@
"title": "Options for Skoda Connect",
"description": "Configure update interval",
"data": {
"update_interval": "Poll frequency (minutes)",
"update_interval": "Poll frequency (seconds)",
"spin": "S-PIN",
"mutable": "Allow interactions with car (actions). Uncheck to make the car 'read only'.",
"convert": "Select distance/unit conversions.",
Expand Down
4 changes: 2 additions & 2 deletions custom_components/skodaconnect/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"data": {
"resources": "Resources to monitor.",
"convert": "Select distance/unit conversions.",
"update_interval": "Poll frequency (minutes).",
"update_interval": "Poll frequency (seconds).",
"debug": "Full API debug logging (requires debug logging enabled in configuration.yaml)"
}
},
Expand Down Expand Up @@ -57,7 +57,7 @@
"title": "Options for Skoda Connect",
"description": "Configure settings",
"data": {
"update_interval": "Poll frequency (minutes)",
"update_interval": "Poll frequency (seconds)",
"spin": "S-PIN",
"mutable": "Allow interactions with car (actions). Uncheck to make the car 'read only'.",
"convert": "Select distance/unit conversions.",
Expand Down
4 changes: 2 additions & 2 deletions custom_components/skodaconnect/translations/it.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"data": {
"resources": "Risorse da monitorare.",
"convert": "Scegli la conversione di distanza/unità.",
"update_interval": "Frequenza di aggiornamento (minuti).",
"update_interval": "Frequenza di aggiornamento (secondi).",
"debug": "API debug logging completo (richiede che il debug logging sia abilitato in configuration.yaml)"
}
},
Expand Down Expand Up @@ -57,7 +57,7 @@
"title": "Opzioni per Skoda Connect",
"description": "Configura impostazioni",
"data": {
"update_interval": "Frequenza di aggiornamento (minuti)",
"update_interval": "Frequenza di aggiornamento (secondi)",
"spin": "S-PIN",
"mutable": "Permetti interazione con l'auto(azioni). Deseleziona se vuoi sono monitorare..",
"convert": "Scegli la conversione di distanza/unità.",
Expand Down
4 changes: 2 additions & 2 deletions custom_components/skodaconnect/translations/pl.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"data": {
"resources": "Zasoby do dodania",
"convert": "Wybierz, jeśli chcesz dokonać konwersji jednostek odległości",
"update_interval": "Częstotliwość sondowania (minuty).",
"update_interval": "Częstotliwość sondowania (sekundy).",
"debug": "Pełne rejestrowanie debugowania interfejsu API (wymaga włączenia rejestrowania debugowania w pliku configuration.yaml)"
}
},
Expand Down Expand Up @@ -57,7 +57,7 @@
"title": "Opcje Skoda Connect",
"description": "Skonfiguruj opcje monitorowania pojazdu Skoda Connect.",
"data": {
"update_interval": "Częstotliwość aktualizacji czujników (minuty)",
"update_interval": "Częstotliwość aktualizacji czujników (sekundy)",
"spin": "S-PIN",
"mutable": "Usuń zaznaczenie, aby samochód był „tylko do odczytu”. Jeśli je zostawisz będziesz mógł wejść w interakcję z samochodem",
"convert": "Wybierz, jeśli chcesz dokonać konwersji jednostek odległości",
Expand Down
4 changes: 2 additions & 2 deletions custom_components/skodaconnect/translations/sv.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"data": {
"resources": "Resurser att övervaka.",
"convert": "Ange enhetsomvandling.",
"update_interval": "Uppdateringsfrekvens (minuter).",
"update_interval": "Uppdateringsfrekvens (sekunder).",
"debug": "Full API debug loggning (kräver debug loggning aktiverat i configuration.yaml)"
}
},
Expand Down Expand Up @@ -57,7 +57,7 @@
"title": "Alternativ för Skoda Connect",
"description": "Alternativ för hantering av Skoda Connect.",
"data": {
"update_interval": "Uppdateringsfrekvens (minuter)",
"update_interval": "Uppdateringsfrekvens (sekunder)",
"spin": "S-PIN",
"mutable": "Tillåt interaktioner med bilen (åtgärder). Avmarkera för att göra bilen 'skrivskyddad'.",
"convert": "Ange enhetsomvandling.",
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
skodaconnect>=1.1.6
skodaconnect>=1.1.7

0 comments on commit d7aa1c1

Please sign in to comment.