-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- items can use ``timedelta`` in ``watch_change`` and ``watch_update`` - Added possibility to specify references in thing config - ``MqttItem`` does no longer inherit from ``Item`` - Added ``MqttPairItem``: An item that consolidates a topic that reports states from a device and a topic that is used to write to a device. - Updated documentation (big thanks to yfaway) - Removed skipping of ``set_value`` and ``post_value`` in docs
- Loading branch information
1 parent
fd39a2a
commit 42da4ad
Showing
22 changed files
with
358 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
__version__ = '0.18.0' | ||
__version__ = '0.18.1' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
from .mqtt_item import MqttItem | ||
from .mqtt_item import MqttItem, MqttBaseItem | ||
from .mqtt_pair_item import MqttPairItem |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
from typing import Optional | ||
|
||
import HABApp.mqtt.mqtt_interface | ||
from . import MqttBaseItem | ||
|
||
|
||
def build_write_topic(read_topic: str) -> Optional[str]: | ||
parts = read_topic.split('/') | ||
if parts[0] == 'zigbee2mqtt': | ||
parts.insert(-1, 'set') | ||
return '/'.join(parts) | ||
|
||
raise ValueError(f'Can not build write topic for "{read_topic}"') | ||
|
||
|
||
class MqttPairItem(MqttBaseItem): | ||
"""An item that represents both a topic that is read only and a corresponding topic that is used to write values""" | ||
|
||
@classmethod | ||
def get_create_item(cls, name: str, write_topic: Optional[str] = None, initial_value=None) -> 'MqttPairItem': | ||
"""Creates a new item in HABApp and returns it or returns the already existing one with the given name. | ||
HABApp tries to automatically derive the write topic from the item name. In cases where this does not | ||
work it can be specified manually. | ||
:param name: item name (topic that reports the state) | ||
:param write_topic: topic that is used to write values or ``None`` (default) to build it automatically | ||
:param initial_value: state the item will have if it gets created | ||
:return: item | ||
""" | ||
assert isinstance(name, str), type(name) | ||
|
||
# try to build write topic | ||
if write_topic is None: | ||
write_topic = build_write_topic(name) | ||
|
||
try: | ||
item = HABApp.core.Items.get_item(name) | ||
except HABApp.core.Items.ItemNotFoundException: | ||
item = cls(name, write_topic=write_topic, initial_value=initial_value) | ||
HABApp.core.Items.add_item(item) | ||
|
||
assert isinstance(item, cls), f'{cls} != {type(item)}' | ||
return item | ||
|
||
def publish(self, payload, qos: int = None, retain: bool = None): | ||
""" | ||
Publish the payload under the write topic from the item. | ||
:param payload: MQTT Payload | ||
:param qos: QoS, can be ``0``, ``1`` or ``2``. If not specified value from configuration file will be used. | ||
:param retain: retain message. If not specified value from configuration file will be used. | ||
:return: 0 if successful | ||
""" | ||
|
||
return HABApp.mqtt.mqtt_interface.MQTT_INTERFACE.publish(self.write_topic, payload, qos=qos, retain=retain) | ||
|
||
def __init__(self, name: str, initial_value=None, write_topic: Optional[str] = None): | ||
super().__init__(name, initial_value) | ||
self.write_topic: Optional[str] = write_topic |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
|
||
Additional class reference | ||
================================== | ||
|
||
Reference for returned classes from some functions. | ||
These are not intended to be created by the user. | ||
|
||
ItemNoUpdateWatch | ||
--------------------------------- | ||
|
||
.. autoclass:: HABApp.core.items.base_item_watch.ItemNoUpdateWatch | ||
:members: | ||
:inherited-members: | ||
:member-order: groupwise | ||
|
||
ItemNoChangeWatch | ||
--------------------------------- | ||
|
||
.. autoclass:: HABApp.core.items.base_item_watch.ItemNoChangeWatch | ||
:members: | ||
:inherited-members: | ||
:member-order: groupwise |
Oops, something went wrong.