Black
This commit is contained in:
1 parent
da05dfe708
commit
4de97abc3a
2676 files changed
+163166
-140084
No files matched your search
@@ -15,18 +15,23 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
|
||||
if discovery_info is None:
|
||||
return
|
||||
|
||||
name = discovery_info['name']
|
||||
base_url = discovery_info['base_url']
|
||||
monitored_conditions = discovery_info['sensors']
|
||||
name = discovery_info["name"]
|
||||
base_url = discovery_info["base_url"]
|
||||
monitored_conditions = discovery_info["sensors"]
|
||||
octoprint_api = hass.data[COMPONENT_DOMAIN][base_url]
|
||||
|
||||
devices = []
|
||||
for octo_type in monitored_conditions:
|
||||
new_sensor = OctoPrintBinarySensor(
|
||||
octoprint_api, octo_type, BINARY_SENSOR_TYPES[octo_type][2],
|
||||
name, BINARY_SENSOR_TYPES[octo_type][3],
|
||||
octoprint_api,
|
||||
octo_type,
|
||||
BINARY_SENSOR_TYPES[octo_type][2],
|
||||
name,
|
||||
BINARY_SENSOR_TYPES[octo_type][3],
|
||||
BINARY_SENSOR_TYPES[octo_type][0],
|
||||
BINARY_SENSOR_TYPES[octo_type][1], 'flags')
|
||||
BINARY_SENSOR_TYPES[octo_type][1],
|
||||
"flags",
|
||||
)
|
||||
devices.append(new_sensor)
|
||||
add_entities(devices, True)
|
||||
|
||||
@@ -34,14 +39,15 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
|
||||
class OctoPrintBinarySensor(BinarySensorDevice):
|
||||
"""Representation an OctoPrint binary sensor."""
|
||||
|
||||
def __init__(self, api, condition, sensor_type, sensor_name, unit,
|
||||
endpoint, group, tool=None):
|
||||
def __init__(
|
||||
self, api, condition, sensor_type, sensor_name, unit, endpoint, group, tool=None
|
||||
):
|
||||
"""Initialize a new OctoPrint sensor."""
|
||||
self.sensor_name = sensor_name
|
||||
if tool is None:
|
||||
self._name = '{} {}'.format(sensor_name, condition)
|
||||
self._name = "{} {}".format(sensor_name, condition)
|
||||
else:
|
||||
self._name = '{} {}'.format(sensor_name, condition)
|
||||
self._name = "{} {}".format(sensor_name, condition)
|
||||
self.sensor_type = sensor_type
|
||||
self.api = api
|
||||
self._state = False
|
||||
@@ -70,8 +76,8 @@ class OctoPrintBinarySensor(BinarySensorDevice):
|
||||
"""Update state of sensor."""
|
||||
try:
|
||||
self._state = self.api.update(
|
||||
self.sensor_type, self.api_endpoint, self.api_group,
|
||||
self.api_tool)
|
||||
self.sensor_type, self.api_endpoint, self.api_group, self.api_tool
|
||||
)
|
||||
except requests.exceptions.ConnectionError:
|
||||
# Error calling the api, already logged in api.update()
|
||||
return
|
||||
Reference in new issue
Block a user