Make pins optional
This commit is contained in:
parent
52b1080ccd
commit
bef0b2b01e
1 changed files with 30 additions and 24 deletions
|
@ -28,10 +28,12 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||||
|
|
||||||
resource = config.get(CONF_RESOURCE)
|
resource = config.get(CONF_RESOURCE)
|
||||||
var_conf = config.get(CONF_MONITORED_VARIABLES)
|
var_conf = config.get(CONF_MONITORED_VARIABLES)
|
||||||
|
pins = config.get('pins', None)
|
||||||
|
|
||||||
if None in (resource, var_conf):
|
|
||||||
|
if resource is None:
|
||||||
_LOGGER.error('Not all required config keys present: %s',
|
_LOGGER.error('Not all required config keys present: %s',
|
||||||
', '.join((CONF_RESOURCE, CONF_MONITORED_VARIABLES)))
|
CONF_RESOURCE)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
@ -49,31 +51,35 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||||
arest = ArestData(resource)
|
arest = ArestData(resource)
|
||||||
|
|
||||||
dev = []
|
dev = []
|
||||||
pins = config.get('pins', None)
|
|
||||||
|
|
||||||
for variable in config['monitored_variables']:
|
if var_conf is not None:
|
||||||
if variable['name'] not in response['variables']:
|
for variable in config['monitored_variables']:
|
||||||
_LOGGER.error('Variable: "%s" does not exist', variable['name'])
|
if variable['name'] not in response['variables']:
|
||||||
continue
|
_LOGGER.error('Variable: "%s" does not exist',
|
||||||
|
variable['name'])
|
||||||
|
continue
|
||||||
|
|
||||||
dev.append(ArestSensor(arest,
|
dev.append(ArestSensor(arest,
|
||||||
resource,
|
resource,
|
||||||
config.get('name', response['name']),
|
config.get('name', response['name']),
|
||||||
variable['name'],
|
variable['name'],
|
||||||
variable=variable['name'],
|
variable=variable['name'],
|
||||||
unit_of_measurement=variable.get(
|
unit_of_measurement=variable.get(
|
||||||
'unit_of_measurement')))
|
'unit_of_measurement')))
|
||||||
|
|
||||||
for pinnum, pin in pins.items():
|
if pins is not None:
|
||||||
dev.append(ArestSensor(ArestData(resource, pinnum),
|
for pinnum, pin in pins.items():
|
||||||
resource,
|
dev.append(ArestSensor(ArestData(resource, pinnum),
|
||||||
config.get('name', response['name']),
|
resource,
|
||||||
pin.get('name'),
|
config.get('name', response['name']),
|
||||||
pin=pinnum,
|
pin.get('name'),
|
||||||
unit_of_measurement=pin.get(
|
pin=pinnum,
|
||||||
'unit_of_measurement'),
|
unit_of_measurement=pin.get(
|
||||||
corr_factor=pin.get('correction_factor', None),
|
'unit_of_measurement'),
|
||||||
decimal_places=pin.get('decimal_places', None)))
|
corr_factor=pin.get('correction_factor',
|
||||||
|
None),
|
||||||
|
decimal_places=pin.get('decimal_places',
|
||||||
|
None)))
|
||||||
|
|
||||||
add_devices(dev)
|
add_devices(dev)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue