1 """Support for OhmConnect."""
3 from __future__
import annotations
5 from datetime
import timedelta
8 import defusedxml.ElementTree
as ET
10 import voluptuous
as vol
13 PLATFORM_SCHEMA
as SENSOR_PLATFORM_SCHEMA,
23 _LOGGER = logging.getLogger(__name__)
25 DEFAULT_NAME =
"OhmConnect Status"
29 PLATFORM_SCHEMA = SENSOR_PLATFORM_SCHEMA.extend(
31 vol.Required(CONF_ID): cv.string,
32 vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string,
40 add_entities: AddEntitiesCallback,
41 discovery_info: DiscoveryInfoType |
None =
None,
43 """Set up the OhmConnect sensor."""
44 name = config.get(CONF_NAME)
45 ohmid = config.get(CONF_ID)
51 """Representation of a OhmConnect sensor."""
54 """Initialize the sensor."""
62 """Return the name of the sensor."""
63 return self.
_name_name
67 """Return the state of the sensor."""
68 if self.
_data_data.
get(
"active") ==
"True":
74 """Return the state attributes."""
75 return {
"Address": self.
_data_data.
get(
"address"),
"ID": self.
_ohmid_ohmid}
77 @Throttle(MIN_TIME_BETWEEN_UPDATES)
79 """Get the latest data from OhmConnect."""
81 url = f
"https://login.ohmconnect.com/verify-ohm-hour/{self._ohmid}"
82 response = requests.get(url, timeout=10)
83 root = ET.fromstring(response.text)
86 self.
_data_data[child.tag] = child.text
87 except requests.exceptions.ConnectionError:
88 _LOGGER.error(
"No route to host/endpoint: %s", url)
def extra_state_attributes(self)
def __init__(self, name, ohmid)
web.Response get(self, web.Request request, str config_key)
def add_entities(account, async_add_entities, tracked)
None setup_platform(HomeAssistant hass, ConfigType config, AddEntitiesCallback add_entities, DiscoveryInfoType|None discovery_info=None)