This commit is contained in:
Paulus Schoutsen committed 2019-07-31 12:25:30 -07:00
1 parent da05dfe708
commit 4de97abc3a
2676 files changed
+163166 -140084

No files matched your search

+42 -35
View File
@@ -6,20 +6,24 @@ import socket
import voluptuous as vol
from homeassistant.const import (
CONF_NAME, CONF_HOST, CONF_PORT, CONF_MONITORED_CONDITIONS)
CONF_NAME,
CONF_HOST,
CONF_PORT,
CONF_MONITORED_CONDITIONS,
)
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.discovery import load_platform
from homeassistant.util import Throttle
from .const import (DOMAIN, SENSOR_TYPES)
from .const import DOMAIN, SENSOR_TYPES
_LOGGER = logging.getLogger(__name__)
DEFAULT_NAME = 'ebusd'
DEFAULT_NAME = "ebusd"
DEFAULT_PORT = 8888
CONF_CIRCUIT = 'circuit'
CONF_CIRCUIT = "circuit"
CACHE_TTL = 900
SERVICE_EBUSD_WRITE = 'ebusd_write'
SERVICE_EBUSD_WRITE = "ebusd_write"
MIN_TIME_BETWEEN_UPDATES = timedelta(seconds=15)
@@ -29,24 +33,27 @@ def verify_ebusd_config(config):
circuit = config[CONF_CIRCUIT]
for condition in config[CONF_MONITORED_CONDITIONS]:
if condition not in SENSOR_TYPES[circuit]:
raise vol.Invalid(
"Condition '" + condition + "' not in '" + circuit + "'.")
raise vol.Invalid("Condition '" + condition + "' not in '" + circuit + "'.")
return config
CONFIG_SCHEMA = vol.Schema({
DOMAIN: vol.Schema(
vol.All({
vol.Required(CONF_CIRCUIT): cv.string,
vol.Required(CONF_HOST): cv.string,
vol.Optional(CONF_PORT, default=DEFAULT_PORT): cv.port,
vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string,
vol.Optional(CONF_MONITORED_CONDITIONS, default=[]):
cv.ensure_list,
},
verify_ebusd_config)
)
}, extra=vol.ALLOW_EXTRA)
CONFIG_SCHEMA = vol.Schema(
{
DOMAIN: vol.Schema(
vol.All(
{
vol.Required(CONF_CIRCUIT): cv.string,
vol.Required(CONF_HOST): cv.string,
vol.Optional(CONF_PORT, default=DEFAULT_PORT): cv.port,
vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string,
vol.Optional(CONF_MONITORED_CONDITIONS, default=[]): cv.ensure_list,
},
verify_ebusd_config,
)
)
},
extra=vol.ALLOW_EXTRA,
)
def setup(hass, config):
@@ -55,24 +62,23 @@ def setup(hass, config):
name = conf[CONF_NAME]
circuit = conf[CONF_CIRCUIT]
monitored_conditions = conf.get(CONF_MONITORED_CONDITIONS)
server_address = (
conf.get(CONF_HOST), conf.get(CONF_PORT))
server_address = (conf.get(CONF_HOST), conf.get(CONF_PORT))
try:
_LOGGER.debug("Ebusd integration setup started")
import ebusdpy
ebusdpy.init(server_address)
hass.data[DOMAIN] = EbusdData(server_address, circuit)
sensor_config = {
CONF_MONITORED_CONDITIONS: monitored_conditions,
'client_name': name,
'sensor_types': SENSOR_TYPES[circuit]
"client_name": name,
"sensor_types": SENSOR_TYPES[circuit],
}
load_platform(hass, 'sensor', DOMAIN, sensor_config, config)
load_platform(hass, "sensor", DOMAIN, sensor_config, config)
hass.services.register(
DOMAIN, SERVICE_EBUSD_WRITE, hass.data[DOMAIN].write)
hass.services.register(DOMAIN, SERVICE_EBUSD_WRITE, hass.data[DOMAIN].write)
_LOGGER.debug("Ebusd integration setup completed")
return True
@@ -97,9 +103,10 @@ class EbusdData:
try:
_LOGGER.debug("Opening socket to ebusd %s", name)
command_result = ebusdpy.read(
self._address, self._circuit, name, stype, CACHE_TTL)
self._address, self._circuit, name, stype, CACHE_TTL
)
if command_result is not None:
if 'ERR:' in command_result:
if "ERR:" in command_result:
_LOGGER.warning(command_result)
else:
self.value[name] = command_result
@@ -110,15 +117,15 @@ class EbusdData:
def write(self, call):
"""Call write methon on ebusd."""
import ebusdpy
name = call.data.get('name')
value = call.data.get('value')
name = call.data.get("name")
value = call.data.get("value")
try:
_LOGGER.debug("Opening socket to ebusd %s", name)
command_result = ebusdpy.write(
self._address, self._circuit, name, value)
command_result = ebusdpy.write(self._address, self._circuit, name, value)
if command_result is not None:
if 'done' not in command_result:
_LOGGER.warning('Write command failed: %s', name)
if "done" not in command_result:
_LOGGER.warning("Write command failed: %s", name)
except RuntimeError as err:
_LOGGER.error(err)