switch.tplink
#
Description#
Plugin to interact with TP-Link smart switches/plugs like the HS100 (https://www.tp-link.com/us/products/details/cat-5516_HS100.html).
Configuration#
switch.tplink:
# [Optional]
# Optional list of IP addresses or name->address mapping if you have a static list of
# TpLink plugs and you want to save on the scan time.
# plugs: # type=Union[Mapping[str, str], List[str], NoneType]
# [Optional]
# Optional list of IP addresses or name->address mapping if you have a static list of
# TpLink bulbs and you want to save on the scan time.
# bulbs: # type=Union[Mapping[str, str], List[str], NoneType]
# [Optional]
# Optional list of IP addresses or name->address mapping if you have a static list of
# TpLink strips and you want to save on the scan time.
# strips: # type=Union[Mapping[str, str], List[str], NoneType]
# [Optional]
# How often the `RunnablePlugin.loop <https://docs.platypush.tech/platypush/plugins/.html#platypush.plugins.RunnablePlugin.loop>`_ function should be
# executed (default: 15 seconds). *NOTE*: For back-compatibility
# reasons, the `poll_seconds` argument is also supported, but it's
# deprecated.
# poll_interval: 15 # type=Optional[float]
# [Optional]
# How long we should wait for any running
# threads/processes to stop before exiting (default: 5 seconds).
# stop_timeout: 5 # type=Optional[float]
# [Optional]
# If set to True then the plugin will not monitor
# for new events. This is useful if you want to run a plugin in
# stateless mode and only leverage its actions, without triggering any
# events. Defaults to False.
# disable_monitor: False # type=bool
Dependencies#
pip
pip install pyHS100
Actions#
Module reference#
- class platypush.plugins.switch.tplink.SwitchTplinkPlugin(*_, **__)[source]#
Bases:
RunnablePlugin
,SwitchEntityManager
Plugin to interact with TP-Link smart switches/plugs like the HS100 (https://www.tp-link.com/us/products/details/cat-5516_HS100.html).
- __init__(plugs: Mapping[str, str] | List[str] | None = None, bulbs: Mapping[str, str] | List[str] | None = None, strips: Mapping[str, str] | List[str] | None = None, **kwargs)[source]#
- Parameters:
plugs – Optional list of IP addresses or name->address mapping if you have a static list of TpLink plugs and you want to save on the scan time.
bulbs – Optional list of IP addresses or name->address mapping if you have a static list of TpLink bulbs and you want to save on the scan time.
strips – Optional list of IP addresses or name->address mapping if you have a static list of TpLink strips and you want to save on the scan time.
- publish_entities(entities: Collection[Any] | None, callback: Callable[[Entity], Any] | None = None, **kwargs) Collection[Entity] #
Publishes a list of entities. The downstream consumers include:
The entity persistence manager
The web server
- Any consumer subscribed to
platypush.message.event.entities.EntityUpdateEvent
events (e.g. web clients)
It also accepts an optional callback that will be called when each of the entities in the set is flushed to the database.
You usually don’t need to override this class (but you may want to extend
transform_entities()
instead if your extension doesn’t natively handle Entity objects).
- set(entity: str, value: Any, **kwargs)#
Set the value of an entity.
- Parameters:
entity – The entity to set the value for. It’s usually the ID of the entity provided by the plugin.
value – The value to set the entity to.
- start()#
Start the plugin.
- status(*_, **__) List[dict] [source]#
Retrieve the current status of the devices. Return format:
[ { "current_consumption": 0.5, "id": "192.168.1.123", "ip": "192.168.1.123", "host": "192.168.1.123", "hw_info": "00:11:22:33:44:55", "name": "My Switch", "on": true, } ]
- stop()#
Stop the plugin.
- toggle(device, **_)[source]#
Toggle the state of a device (on/off)
- Parameters:
device (str) – Device IP, hostname or alias
- transform_entities(entities: Collection[pyHS100.SmartDevice])[source]#
This method takes a list of entities in any (plugin-specific) format and converts them into a standardized collection of Entity objects. Since this method is called by
publish_entities()
before entity updates are published, you may usually want to extend it to pre-process the entities managed by your extension into the standard format before they are stored and published to all the consumers.
- wait_stop(timeout=None)#
Wait until a stop event is received.