Disable pylint warning for callable classes
parent
427944cc44
commit
715abf241e
|
@ -129,6 +129,7 @@ def setup(hass, config):
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
# pylint: disable=too-few-public-methods
|
||||||
class _JsonFmtParser(object):
|
class _JsonFmtParser(object):
|
||||||
""" Implements a json parser on xpath"""
|
""" Implements a json parser on xpath"""
|
||||||
def __init__(self, jsonpath):
|
def __init__(self, jsonpath):
|
||||||
|
@ -139,16 +140,17 @@ class _JsonFmtParser(object):
|
||||||
return match[0].value if len(match) > 0 else payload
|
return match[0].value if len(match) > 0 else payload
|
||||||
|
|
||||||
|
|
||||||
|
# pylint: disable=too-few-public-methods
|
||||||
class FmtParser(object):
|
class FmtParser(object):
|
||||||
""" wrapper for all supported formats """
|
""" wrapper for all supported formats """
|
||||||
def __init__(self, fmt):
|
def __init__(self, fmt):
|
||||||
self._parser = lambda x: x
|
self._parse = lambda x: x
|
||||||
if fmt:
|
if fmt:
|
||||||
if fmt.startswith('json:'):
|
if fmt.startswith('json:'):
|
||||||
self._parser = _JsonFmtParser(fmt[5:])
|
self._parse = _JsonFmtParser(fmt[5:])
|
||||||
|
|
||||||
def __call__(self, payload):
|
def __call__(self, payload):
|
||||||
return self._parser(payload)
|
return self._parse(payload)
|
||||||
|
|
||||||
|
|
||||||
# This is based on one of the paho-mqtt examples:
|
# This is based on one of the paho-mqtt examples:
|
||||||
|
|
|
@ -46,11 +46,11 @@ class MqttSensor(Entity):
|
||||||
self._state_topic = state_topic
|
self._state_topic = state_topic
|
||||||
self._qos = qos
|
self._qos = qos
|
||||||
self._unit_of_measurement = unit_of_measurement
|
self._unit_of_measurement = unit_of_measurement
|
||||||
self._parser = mqtt.FmtParser(state_format)
|
self._parse = mqtt.FmtParser(state_format)
|
||||||
|
|
||||||
def message_received(topic, payload, qos):
|
def message_received(topic, payload, qos):
|
||||||
""" A new MQTT message has been received. """
|
""" A new MQTT message has been received. """
|
||||||
self._state = self._parser(payload)
|
self._state = self._parse(payload)
|
||||||
self.update_ha_state()
|
self.update_ha_state()
|
||||||
|
|
||||||
mqtt.subscribe(hass, self._state_topic, message_received, self._qos)
|
mqtt.subscribe(hass, self._state_topic, message_received, self._qos)
|
||||||
|
|
|
@ -55,11 +55,11 @@ class MqttSwitch(SwitchDevice):
|
||||||
self._payload_on = payload_on
|
self._payload_on = payload_on
|
||||||
self._payload_off = payload_off
|
self._payload_off = payload_off
|
||||||
self._optimistic = optimistic
|
self._optimistic = optimistic
|
||||||
self._parser = mqtt.FmtParser(state_format)
|
self._parse = mqtt.FmtParser(state_format)
|
||||||
|
|
||||||
def message_received(topic, payload, qos):
|
def message_received(topic, payload, qos):
|
||||||
""" A new MQTT message has been received. """
|
""" A new MQTT message has been received. """
|
||||||
payload = self._parser(payload)
|
payload = self._parse(payload)
|
||||||
if payload == self._payload_on:
|
if payload == self._payload_on:
|
||||||
self._state = True
|
self._state = True
|
||||||
self.update_ha_state()
|
self.update_ha_state()
|
||||||
|
|
Loading…
Reference in New Issue