Tweak MQTT Motor component

This commit is contained in:
Paulus Schoutsen committed 2015-11-28 01:02:35 -08:00
1 parent 9f01d7abca
commit 6809a881fa
3 files changed
+60 -24

No files matched your search

+14 -6
View File
@@ -17,7 +17,6 @@ from homeassistant.const import (
DOMAIN = 'motor'
DEPENDENCIES = []
SCAN_INTERVAL = 15
GROUP_NAME_ALL_MOTORS = 'all motors'
@@ -30,6 +29,8 @@ DISCOVERY_PLATFORMS = {}
_LOGGER = logging.getLogger(__name__)
ATTR_CURRENT_POSITION = 'current_position'
def is_open(hass, entity_id=None):
""" Returns if the motor is open based on the statemachine. """
@@ -114,17 +115,24 @@ class MotorDevice(Entity):
@property
def state_attributes(self):
""" Returns optional state attributes. """
return None
""" Return the state attributes. """
current = self.current_position
if current is None:
return None
return {
ATTR_CURRENT_POSITION: current
}
def open(self, **kwargs):
""" Open the device. """
""" Open the motor. """
raise NotImplementedError()
def close(self, **kwargs):
""" Close the device. """
""" Close the motor. """
raise NotImplementedError()
def stop(self, **kwargs):
""" Stop the device. """
""" Stop the motor. """
raise NotImplementedError()
-16
View File
@@ -18,10 +18,7 @@ DEFAULT_PAYLOAD_OPEN = "OPEN"
DEFAULT_PAYLOAD_CLOSE = "CLOSE"
DEFAULT_PAYLOAD_STOP = "STOP"
ATTR_CURRENT_POSITION = 'current_position'
# pylint: disable=unused-argument
def setup_platform(hass, config, add_devices_callback, discovery_info=None):
""" Add MQTT Motor """
@@ -88,11 +85,6 @@ class MqttMotor(MotorDevice):
None is unknown, 0 is closed, 100 is fully open. """
return self._state
@property
def is_open(self):
""" True if device is current position is not zero. """
return self._state > 0
def open(self, **kwargs):
""" Open the device. """
mqtt.publish(self.hass, self._command_topic, self._payload_open,
@@ -107,11 +99,3 @@ class MqttMotor(MotorDevice):
""" Stop the device. """
mqtt.publish(self.hass, self._command_topic, self._payload_stop,
self._qos)
@property
def state_attributes(self):
""" Return the state attributes. """
state_attr = {}
if self._state is not None:
state_attr[ATTR_CURRENT_POSITION] = self._state
return state_attr