-
Notifications
You must be signed in to change notification settings - Fork 0
/
slxevsemanual.py
81 lines (67 loc) · 2.13 KB
/
slxevsemanual.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
""" slxmodule for connecting with OpenEVSE"""
from homeassistant.helpers.event import async_track_state_change_event
from homeassistant.helpers import entity_registry, device_registry
from homeassistant.helpers.entity_registry import EntityRegistry
from homeassistant.util import slugify
import logging
from typing import Any
from enum import Enum
from homeassistant.core import (
HomeAssistant,
Event,
Callable,
State,
callback,
)
from .slxevse import SLXEvse
from .const import (
CHARGER_MODES,
CHR_MODE_UNKNOWN,
CHR_MODE_STOPPED,
CHR_MODE_PVCHARGE,
CHR_MODE_NORMAL,
)
_LOGGER = logging.getLogger(__name__)
class SLXManualEvse(SLXEvse):
"""Class for manual EVSE connection"""
def __init__(
self,
hass: HomeAssistant,
):
_LOGGER.debug("SLXManualEvse")
super().__init__(hass)
def connect(
self,
cb_sessionenergy: Callable[[Event], Any],
session_energy_name: str,
cb_plug: Callable[[Event], Any],
plug_name: str,
) -> bool:
self._subscribe_entity(session_energy_name, cb_sessionenergy)
self._subscribe_entity(plug_name, cb_plug)
self._session_energy_name = session_energy_name
self._plug_name = plug_name
return True
def get_session_energy(self) -> float | None:
entity_state = self.hass.states.get(self._session_energy_name)
if entity_state is None:
_LOGGER.warning(
"Get_session_energy - value of %s is None", self._session_energy_name
)
return None
try:
value_str = entity_state.state
value = float(value_str)
return value
except ValueError:
_LOGGER.warning("Get_session_energy - invalid state= %s", value_str)
return None
return None
def set_charger_mode(self, mode: str) -> None:
if not mode in CHARGER_MODES:
_LOGGER.warning("Invalid charing mode %s", mode)
return
_LOGGER.info("Set charger mode %s", mode)
if mode == self.charge_mode:
return
self.charge_mode = mode