fix flak8 warnings
parent
799043dc0a
commit
030686a978
|
@ -129,22 +129,24 @@ def setup(hass, config):
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
class FmtParser(object):
|
class _JsonFmtParser(object):
|
||||||
""" wrapper for all supported formats """
|
|
||||||
|
|
||||||
class _JsonFmtParser(object):
|
|
||||||
""" Implements a json parser on xpath"""
|
""" Implements a json parser on xpath"""
|
||||||
def __init__(self, jsonpath):
|
def __init__(self, jsonpath):
|
||||||
self._expr = jsonpath_rw.parse(jsonpath)
|
self._expr = jsonpath_rw.parse(jsonpath)
|
||||||
|
|
||||||
def __call__(self, payload):
|
def __call__(self, payload):
|
||||||
match = self._expr.find(json.loads(payload))
|
match = self._expr.find(json.loads(payload))
|
||||||
return match[0].value if len(match) > 0 else None
|
return match[0].value if len(match) > 0 else payload
|
||||||
|
|
||||||
|
|
||||||
|
class FmtParser(object):
|
||||||
|
""" wrapper for all supported formats """
|
||||||
def __init__(self, fmt):
|
def __init__(self, fmt):
|
||||||
if fmt.startswith('json:'):
|
if fmt.startswith('json:'):
|
||||||
self._parser = FmtParser._JsonFmtParser(fmt[5:])
|
self._parser = _JsonFmtParser(fmt[5:])
|
||||||
else:
|
else:
|
||||||
self._parser = lambda x: x
|
self._parser = lambda x: x
|
||||||
|
|
||||||
def __call__(self, payload):
|
def __call__(self, payload):
|
||||||
return self._parser(payload)
|
return self._parser(payload)
|
||||||
|
|
||||||
|
|
|
@ -7,8 +7,6 @@ For more details about this platform, please refer to the documentation at
|
||||||
https://home-assistant.io/components/sensor.mqtt/
|
https://home-assistant.io/components/sensor.mqtt/
|
||||||
"""
|
"""
|
||||||
import logging
|
import logging
|
||||||
import json
|
|
||||||
import jsonpath_rw
|
|
||||||
from homeassistant.helpers.entity import Entity
|
from homeassistant.helpers.entity import Entity
|
||||||
import homeassistant.components.mqtt as mqtt
|
import homeassistant.components.mqtt as mqtt
|
||||||
|
|
||||||
|
@ -40,7 +38,8 @@ def setup_platform(hass, config, add_devices_callback, discovery_info=None):
|
||||||
# pylint: disable=too-many-arguments, too-many-instance-attributes
|
# pylint: disable=too-many-arguments, too-many-instance-attributes
|
||||||
class MqttSensor(Entity):
|
class MqttSensor(Entity):
|
||||||
""" Represents a sensor that can be updated using MQTT. """
|
""" Represents a sensor that can be updated using MQTT. """
|
||||||
def __init__(self, hass, name, state_topic, qos, unit_of_measurement,state_format):
|
def __init__(self, hass, name, state_topic, qos, unit_of_measurement,
|
||||||
|
state_format):
|
||||||
self._state = "-"
|
self._state = "-"
|
||||||
self._hass = hass
|
self._hass = hass
|
||||||
self._name = name
|
self._name = name
|
||||||
|
|
Loading…
Reference in New Issue