fix flak8 warnings
parent
799043dc0a
commit
030686a978
|
@ -129,24 +129,26 @@ def setup(hass, config):
|
|||
return True
|
||||
|
||||
|
||||
class FmtParser(object):
|
||||
""" wrapper for all supported formats """
|
||||
|
||||
class _JsonFmtParser(object):
|
||||
class _JsonFmtParser(object):
|
||||
""" Implements a json parser on xpath"""
|
||||
def __init__(self, jsonpath):
|
||||
self._expr = jsonpath_rw.parse(jsonpath)
|
||||
self._expr = jsonpath_rw.parse(jsonpath)
|
||||
|
||||
def __call__(self, payload):
|
||||
match = self._expr.find(json.loads(payload))
|
||||
return match[0].value if len(match) > 0 else None
|
||||
|
||||
def __init__(self, fmt):
|
||||
if fmt.startswith('json:'):
|
||||
self._parser = FmtParser._JsonFmtParser(fmt[5:])
|
||||
else:
|
||||
self._parser = lambda x: x
|
||||
def __call__(self, payload):
|
||||
return self._parser(payload)
|
||||
match = self._expr.find(json.loads(payload))
|
||||
return match[0].value if len(match) > 0 else payload
|
||||
|
||||
|
||||
class FmtParser(object):
|
||||
""" wrapper for all supported formats """
|
||||
def __init__(self, fmt):
|
||||
if fmt.startswith('json:'):
|
||||
self._parser = _JsonFmtParser(fmt[5:])
|
||||
else:
|
||||
self._parser = lambda x: x
|
||||
|
||||
def __call__(self, payload):
|
||||
return self._parser(payload)
|
||||
|
||||
|
||||
# This is based on one of the paho-mqtt examples:
|
||||
|
|
|
@ -7,8 +7,6 @@ For more details about this platform, please refer to the documentation at
|
|||
https://home-assistant.io/components/sensor.mqtt/
|
||||
"""
|
||||
import logging
|
||||
import json
|
||||
import jsonpath_rw
|
||||
from homeassistant.helpers.entity import Entity
|
||||
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
|
||||
class MqttSensor(Entity):
|
||||
""" 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._hass = hass
|
||||
self._name = name
|
||||
|
|
Loading…
Reference in New Issue