From c6aa92cfc82c58d743f95994ca5e35a54e191c89 Mon Sep 17 00:00:00 2001 From: cyberjunky Date: Sat, 20 Jan 2024 15:23:43 +0000 Subject: [PATCH] Switched to serial-number instead of location-id --- README.md | 8 ++++---- custom_components/shell_recharge_ev/__init__.py | 10 +++++----- .../shell_recharge_ev/config_flow.py | 17 +++++------------ custom_components/shell_recharge_ev/const.py | 2 +- .../shell_recharge_ev/manifest.json | 2 +- custom_components/shell_recharge_ev/sensor.py | 7 +++---- .../shell_recharge_ev/translations/en.json | 5 ++--- requirements.txt | 2 +- 8 files changed, 22 insertions(+), 31 deletions(-) diff --git a/README.md b/README.md index a1c4cd8..0bba9a0 100644 --- a/README.md +++ b/README.md @@ -11,9 +11,9 @@ _Integration to integrate with [shell_recharge_ev][shell_recharge_ev]._ **This integration will set up the following platforms.** -| Platform | Description | -| -------- | ---------------------------------------- | -| `sensor` | Contains useful information for charger. | +| Platform | Description | +| -------- | ------------------------------------------------------ | +| `sensor` | Contains detailed information for charger at location. | ## Installation @@ -33,7 +33,7 @@ _Integration to integrate with [shell_recharge_ev][shell_recharge_ev]._ ## Configuration -Configuration is done in the UI +To find the serial numbers, find charger(s) to monitor here https://ui-map.shellrecharge.com/ and use the Serial number under details. ## Screenshots diff --git a/custom_components/shell_recharge_ev/__init__.py b/custom_components/shell_recharge_ev/__init__.py index 4ba0c26..4aeaa46 100644 --- a/custom_components/shell_recharge_ev/__init__.py +++ b/custom_components/shell_recharge_ev/__init__.py @@ -10,7 +10,7 @@ from homeassistant.helpers.aiohttp_client import async_get_clientsession from homeassistant.helpers.update_coordinator import DataUpdateCoordinator -from .const import DOMAIN, UPDATE_INTERVAL, LocationId +from .const import DOMAIN, UPDATE_INTERVAL, SerialNumber _LOGGER = logging.getLogger(__name__) PLATFORMS: list[Platform] = [Platform.SENSOR] @@ -24,7 +24,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: api = shellrechargeev.Api(websession=async_get_clientsession(hass)) coordinator = ShellRechargeEVDataUpdateCoordinator( - hass, api, entry.data["location_id"] + hass, api, entry.data["serial_number"] ) hass.data[DOMAIN][entry.entry_id] = coordinator await coordinator.async_config_entry_first_refresh() @@ -48,7 +48,7 @@ class ShellRechargeEVDataUpdateCoordinator(DataUpdateCoordinator): # type: igno """My custom coordinator.""" def __init__( - self, hass: HomeAssistant, api: shellrechargeev.Api, location_id: LocationId + self, hass: HomeAssistant, api: shellrechargeev.Api, serial_number: SerialNumber ) -> None: """Initialize my coordinator.""" super().__init__( @@ -58,7 +58,7 @@ def __init__( update_interval=UPDATE_INTERVAL, ) self.api = api - self.location_id = location_id + self.serial_number = serial_number async def _async_update_data(self) -> shellrechargeev.Location: """Fetch data from API endpoint. @@ -66,4 +66,4 @@ async def _async_update_data(self) -> shellrechargeev.Location: This is the place to pre-process the data to lookup tables so entities can quickly look up their data. """ - return await self.api.location_by_id(self.location_id) + return await self.api.location_by_id(self.serial_number) diff --git a/custom_components/shell_recharge_ev/config_flow.py b/custom_components/shell_recharge_ev/config_flow.py index 1cd3aca..280a9f6 100644 --- a/custom_components/shell_recharge_ev/config_flow.py +++ b/custom_components/shell_recharge_ev/config_flow.py @@ -1,7 +1,6 @@ """Config flow for shell_recharge_ev integration.""" from __future__ import annotations -import re from asyncio import CancelledError from typing import Any @@ -14,7 +13,7 @@ from .const import DOMAIN -RECHARGE_SCHEMA = vol.Schema({vol.Required("location_id"): str}) +RECHARGE_SCHEMA = vol.Schema({vol.Required("serial_number"): str}) class ShellRechargeEVFlowHandler(config_entries.ConfigFlow, domain=DOMAIN): # type: ignore[misc, call-arg] @@ -31,25 +30,19 @@ async def async_step_user( return self.async_show_form(step_id="user", data_schema=RECHARGE_SCHEMA) try: - match = re.fullmatch( - r"^\s*(?:[0-9]{7})\s*$", - user_input["location_id"], - ) - if not match: - errors["location_id"] = "malformed_location_id" - api = shellrechargeev.Api(websession=async_get_clientsession(self.hass)) - if not await api.location_by_id(user_input["location_id"]): + if not await api.location_by_id(user_input["serial_number"]): errors["base"] = "empty_response" except (ClientError, TimeoutError, CancelledError): errors["base"] = "cannot_connect" if not errors: - await self.async_set_unique_id(user_input["location_id"]) + await self.async_set_unique_id(user_input["serial_number"]) self._abort_if_unique_id_configured(updates=user_input) return self.async_create_entry( - title=f"Shell Recharge {user_input['location_id']}", data=user_input + title=f"Shell Recharge Charge Point ID {user_input['serial_number']}", + data=user_input, ) return self.async_show_form( diff --git a/custom_components/shell_recharge_ev/const.py b/custom_components/shell_recharge_ev/const.py index 1529132..1132a25 100644 --- a/custom_components/shell_recharge_ev/const.py +++ b/custom_components/shell_recharge_ev/const.py @@ -2,6 +2,6 @@ from datetime import timedelta DOMAIN = "shell_recharge_ev" -LocationId = str +SerialNumber = str EvseId = str UPDATE_INTERVAL = timedelta(minutes=5) diff --git a/custom_components/shell_recharge_ev/manifest.json b/custom_components/shell_recharge_ev/manifest.json index 9b1ce3a..c5c0076 100644 --- a/custom_components/shell_recharge_ev/manifest.json +++ b/custom_components/shell_recharge_ev/manifest.json @@ -11,7 +11,7 @@ "iot_class": "cloud_polling", "issue_tracker": "https://github.com/cyberjunky/home-assistant_shell_recharge_ev/issues", "requirements": [ - "python-shellrechargeev==0.1.5" + "python-shellrechargeev==0.1.7" ], "version": "0.1.3" } diff --git a/custom_components/shell_recharge_ev/sensor.py b/custom_components/shell_recharge_ev/sensor.py index 12d7c94..8e352ee 100644 --- a/custom_components/shell_recharge_ev/sensor.py +++ b/custom_components/shell_recharge_ev/sensor.py @@ -66,7 +66,7 @@ def __init__( identifiers={(DOMAIN, self._attr_name)}, entry_type=None, ) - self._attr_options = list(typing.get_args(shellrechargeev.Status)) + self._attr_options = list(typing.get_args(shellrechargeev.models.Status)) self._read_coordinator_data() def _get_evse(self) -> Any: @@ -74,7 +74,7 @@ def _get_evse(self) -> Any: if evse.uid == self.evse_id: return evse - def _choose_icon(self, connectors: list[shellrechargeev.Connector]) -> str: + def _choose_icon(self, connectors: list[shellrechargeev.models.Connector]) -> str: iconmap: dict[str, str] = { "Type1": "mdi:ev-plug-type1", "Type2": "mdi:ev-plug-type2", @@ -114,14 +114,13 @@ def _read_coordinator_data(self) -> None: "tariff_updated": connector.tariff.updated, "tariff_updated_by": connector.tariff.updatedBy, "tariff_structure": connector.tariff.structure, - "tariff_vat": self.location.vat, "connector_power_type": connector.electricalProperties.powerType, "connector_voltage": connector.electricalProperties.voltage, "connector_ampere": connector.electricalProperties.amperage, "connector_max_power": connector.electricalProperties.maxElectricPower, "connector_fixed_cable": connector.fixedCable, "accessibility": self.location.accessibilityV2.status, - "recharge_id": str(self.location.uid), + "external_id": str(self.location.externalId), "evse_id": str(evse.evseId), "opentwentyfourseven": self.location.openTwentyFourSeven, } diff --git a/custom_components/shell_recharge_ev/translations/en.json b/custom_components/shell_recharge_ev/translations/en.json index ada6e50..04fff0b 100644 --- a/custom_components/shell_recharge_ev/translations/en.json +++ b/custom_components/shell_recharge_ev/translations/en.json @@ -5,14 +5,13 @@ }, "error": { "cannot_connect": "Failed to connect", - "empty_response": "Empty reponse from shellrecharge.com. Either invalid LOCATION-ID or no data for it.", - "malformed_location_id": "Malformed LOCATION-ID", + "empty_response": "Empty reponse from shellrecharge.com. Either invalid SERIAL-NUMBER or no data found for it.", "unknown": "Unexpected error" }, "step": { "user": { "data": { - "location_id": "LOCATION-ID (e.g. 3357677)" + "serial_number": "SERIAL-NUMBER (e.g. 0F80EA26-5F5D-4728-B5E5-268BE55B9191)" } } } diff --git a/requirements.txt b/requirements.txt index 26f1793..4f7c842 100644 --- a/requirements.txt +++ b/requirements.txt @@ -4,7 +4,7 @@ mypy==1.8.0 pip>=21.0,<23.4 pre-commit==3.6.0 pylint==3.0.3 -python-shellrechargeev==0.1.5 +python-shellrechargeev==0.1.7 ruff==0.1.13 types-cachetools vulture==2.11