1+ # pyright: reportIncompatibleVariableOverride=false
2+ #
3+ # Home Assistant Custom Component: Enpal Webparser
4+ #
5+ # File: button.py
6+ #
7+ # Description:
8+ # Home Assistant button platform for Enpal wallbox actions.
9+ # Provides start/stop charging and mode selection buttons for Enpal wallbox integration.
10+ #
11+ # Author: Oliver Stock (github.com/derolli1976)
12+ # License: MIT
13+ # Repository: https://github.com/derolli1976/enpal
14+ #
15+ # Compatible with Home Assistant Core 2024.x and later.
16+ #
17+ # See README.md for setup and usage instructions.
18+ #
19+
20+ from functools import cached_property
121import logging
2- import aiohttp
3- from homeassistant .helpers .aiohttp_client import async_get_clientsession
22+
423from homeassistant .components .button import ButtonEntity
24+ from homeassistant .helpers .aiohttp_client import async_get_clientsession
25+ from homeassistant .helpers .device_registry import DeviceInfo
526from homeassistant .helpers .entity import EntityCategory
27+
628from .const import DOMAIN , DEFAULT_WALLBOX_API_ENDPOINT
729
30+
831_LOGGER = logging .getLogger (__name__ )
932
1033MODES = {
1336 "solar" : "Solar" ,
1437}
1538
39+
1640async def async_setup_entry (hass , config_entry , async_add_entities ):
1741 if not config_entry .options .get ("use_wallbox_addon" , False ):
1842 _LOGGER .debug ("[Enpal] Wallbox add-on is disabled, skipping button setup." )
1943 return
2044
2145 _LOGGER .info ("[Enpal] Setting up Wallbox buttons" )
22- #options = config_entry.options
23- #base_url = "http://localhost:36725/wallbox"
46+
2447 base_url = DEFAULT_WALLBOX_API_ENDPOINT
2548
2649 buttons = [
2750 EnpalWallboxButton (hass , "Ladevorgang starten" , f"{ base_url } /start" , "start" ),
2851 EnpalWallboxButton (hass , "Ladevorgang stoppen" , f"{ base_url } /stop" , "stop" ),
2952 ]
53+
3054 for key , label in MODES .items ():
3155 button_name = f"Modus { label } aktivieren"
3256 buttons .append (EnpalWallboxButton (hass , button_name , f"{ base_url } /set_{ key } " , f"set_{ key } " ))
@@ -45,14 +69,14 @@ def __init__(self, hass, name, url, unique_id):
4569 self ._attr_entity_category = EntityCategory .CONFIG
4670 _LOGGER .debug ("[Enpal] Created button entity: %s (URL: %s)" , self ._attr_name , self ._url )
4771
48- @property
49- def device_info (self ):
50- return {
51- " identifiers" : {(DOMAIN , "enpal_device" )},
52- " name" : "Enpal Webgerät" ,
53- " manufacturer" : "Enpal" ,
54- " model" : "Webparser" ,
55- }
72+ @cached_property
73+ def device_info (self ) -> DeviceInfo :
74+ return DeviceInfo (
75+ identifiers = {(DOMAIN , "enpal_device" )},
76+ name = "Enpal Webgerät" ,
77+ manufacturer = "Enpal" ,
78+ model = "Webparser" ,
79+ )
5680
5781 async def async_press (self ):
5882 _LOGGER .info ("[Enpal] Button pressed: %s" , self ._attr_name )
@@ -68,14 +92,13 @@ async def async_press(self):
6892 _LOGGER .exception ("[Enpal] Wallbox request failed: %s" , e )
6993
7094 await self ._hass .services .async_call (
71- "homeassistant" , "update_entity" ,
95+ "homeassistant" ,
96+ "update_entity" ,
7297 {
7398 "entity_id" : [
7499 "sensor.wallbox_lademodus" ,
75- "sensor.wallbox_status"
100+ "sensor.wallbox_status" ,
76101 ]
77102 },
78103 blocking = True
79104 )
80-
81-
0 commit comments