Skip to content

Commit

Permalink
Merge pull request #10 from leeyuentuen/dev
Browse files Browse the repository at this point in the history
Merge dev to master (release V2)
  • Loading branch information
leeyuentuen authored Jul 4, 2023
2 parents 01ecdff + fe71f71 commit 9a86f08
Show file tree
Hide file tree
Showing 11 changed files with 1,261 additions and 456 deletions.
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@

# Alfen Wallbox - HomeAssistant Integration

This is a custom component to allow control of Alfen Wallboxes in [HomeAssistant](https://home-assistant.io).

The component is a fork of the [Garo Wallbox custom integration](https://github.com/sockless-coding/garo_wallbox).

![image](https://github.com/leeyuentuen/alfen_wallbox/assets/1487966/a25af9bc-a6b3-496d-9c04-6812825cb375)
![Screenshot 2023-07-02 at 18 09 47](https://github.com/leeyuentuen/alfen_wallbox/assets/1487966/322e9e05-117f-4adc-b159-7177533fde01)

![Screenshot 2023-07-02 at 18 09 58](https://github.com/leeyuentuen/alfen_wallbox/assets/1487966/310f0537-9bc4-49a0-9552-0c8414b97425)

Add Solar charging data:
![Screenshot 2023-07-02 at 18 10 13](https://github.com/leeyuentuen/alfen_wallbox/assets/1487966/f5e2670d-4bd8-40d2-bbbe-f0628cff6273)

<img width="336" alt="image" src="https://github.com/leeyuentuen/alfen_wallbox/assets/1487966/4884a7ce-d06b-4ebb-bfb3-e37002fa6629">

Example of running in Services:
Note; the name of the configured charging point is "wallbox" in these examples.
Expand Down
51 changes: 22 additions & 29 deletions custom_components/alfen_wallbox/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,20 @@
import asyncio
from datetime import timedelta
import logging
from typing import Any, Dict

from aiohttp import ClientConnectionError
from async_timeout import timeout

from homeassistant.components.sensor import DOMAIN as SENSOR_DOMAIN
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import (
ATTR_NAME,
CONF_HOST,
CONF_NAME,
CONF_USERNAME,
CONF_PASSWORD,
Platform,
)
from homeassistant.core import HomeAssistant
from homeassistant.exceptions import ConfigEntryNotReady
from homeassistant.helpers import device_registry as dr
from homeassistant.helpers.aiohttp_client import async_get_clientsession
from homeassistant.helpers.entity import Entity
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed
from homeassistant.helpers.typing import HomeAssistantType

from .alfen import AlfenDevice

Expand All @@ -32,56 +25,56 @@
TIMEOUT,
)

PLATFORMS = [SENSOR_DOMAIN]
PLATFORMS = [
Platform.SENSOR,
Platform.SELECT,
Platform.BINARY_SENSOR,
Platform.SWITCH,
Platform.NUMBER,
]
SCAN_INTERVAL = timedelta(seconds=60)

_LOGGER = logging.getLogger(__name__)


async def async_setup(hass: HomeAssistant, config: Dict) -> bool:
async def async_setup(hass: HomeAssistant, config: dict) -> bool:
"""Set up the Alfen Wallbox component."""
hass.data.setdefault(DOMAIN, {})
return True


async def async_setup_entry(hass: HomeAssistantType, entry: ConfigEntry):
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry):
conf = entry.data
device = await alfen_setup(
hass, conf[CONF_HOST], conf[CONF_NAME], conf[CONF_USERNAME], conf[CONF_PASSWORD]
)
if not device:
return False
hass.data.setdefault(DOMAIN, {}).update({entry.entry_id: device})
for component in PLATFORMS:
hass.async_create_task(
hass.config_entries.async_forward_entry_setup(entry, component)
)

"""device_registry = await dr.async_get_registry(hass)
device_registry.async_get_or_create(**device.device_info)"""

hass.data.setdefault(DOMAIN, {})
hass.data[DOMAIN][entry.entry_id] = device

# hass.data.setdefault(DOMAIN, {}).update({entry.entry_id: device})

await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)

return True


async def async_unload_entry(hass, config_entry):
async def async_unload_entry(hass: HomeAssistant, config_entry: ConfigEntry):
"""Unload a config entry."""
_LOGGER.debug("async_unload_entry: %s", config_entry)

unload_ok = all(
await asyncio.gather(
*[
hass.config_entries.async_forward_entry_unload(config_entry, component)
for component in PLATFORMS
]
)
)
unload_ok = await hass.config_entries.async_unload_platforms(config_entry, PLATFORMS)

hass.data[DOMAIN].pop(config_entry.entry_id)
if not hass.data[DOMAIN]:
hass.data.pop(DOMAIN)

return unload_ok


async def alfen_setup(hass, host, name, username, password):
async def alfen_setup(hass: HomeAssistant, host: str, name: str, username: str, password: str):
"""Create a Alfen instance only once."""

session = hass.helpers.aiohttp_client.async_get_clientsession()
Expand Down
Loading

0 comments on commit 9a86f08

Please sign in to comment.