6
6
from typing import Dict
7
7
8
8
from homeassistant .config_entries import ConfigEntry
9
- from homeassistant .const import TIME_MINUTES
9
+ from homeassistant .const import STATE_OK , STATE_UNAVAILABLE , TIME_MINUTES
10
10
from homeassistant .core import HomeAssistant
11
11
from homeassistant .helpers import device_registry , entity_component , entity_registry
12
12
import voluptuous as vol
@@ -163,6 +163,7 @@ async def on_connect(self, websocket, path: str):
163
163
except Exception as e :
164
164
_LOGGER .info (f"Exception occurred:\n { e } " )
165
165
finally :
166
+ self .charge_points [cp_id ].status = STATE_UNAVAILABLE
166
167
_LOGGER .info (f"Charger { cp_id } disconnected from { self .host } :{ self .port } ." )
167
168
168
169
def get_metric (self , cp_id : str , measurand : str ):
@@ -183,6 +184,12 @@ def get_extra_attr(self, cp_id: str, measurand: str):
183
184
return self .charge_points [cp_id ].get_extra_attr (measurand )
184
185
return None
185
186
187
+ def get_available (self , cp_id : str ):
188
+ """Return whether the charger is available."""
189
+ if cp_id in self .charge_points :
190
+ return self .charge_points [cp_id ].status == STATE_OK
191
+ return False
192
+
186
193
async def set_charger_state (
187
194
self , cp_id : str , service_name : str , state : bool = True
188
195
):
@@ -349,6 +356,7 @@ async def handle_get_configuration(call):
349
356
handle_update_firmware ,
350
357
UFW_SERVICE_DATA_SCHEMA ,
351
358
)
359
+ self .status = STATE_OK
352
360
except (NotImplementedError ) as e :
353
361
_LOGGER .error ("Configuration of the charger failed: %s" , e )
354
362
0 commit comments