Skip to content

Commit

Permalink
Switched to serial-number instead of location-id
Browse files Browse the repository at this point in the history
  • Loading branch information
cyberjunky committed Jan 20, 2024
1 parent b765e3f commit c6aa92c
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 31 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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

Expand Down
10 changes: 5 additions & 5 deletions custom_components/shell_recharge_ev/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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()
Expand All @@ -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__(
Expand All @@ -58,12 +58,12 @@ 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.
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)
17 changes: 5 additions & 12 deletions custom_components/shell_recharge_ev/config_flow.py
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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]
Expand All @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion custom_components/shell_recharge_ev/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
from datetime import timedelta

DOMAIN = "shell_recharge_ev"
LocationId = str
SerialNumber = str
EvseId = str
UPDATE_INTERVAL = timedelta(minutes=5)
2 changes: 1 addition & 1 deletion custom_components/shell_recharge_ev/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
7 changes: 3 additions & 4 deletions custom_components/shell_recharge_ev/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,15 @@ 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:
for evse in self.coordinator.data.evses:
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",
Expand Down Expand Up @@ -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,
}
Expand Down
5 changes: 2 additions & 3 deletions custom_components/shell_recharge_ev/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -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)"
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit c6aa92c

Please sign in to comment.