import logging
from typing import Optional, Dict, Any
from platypush.message.event import Event
[docs]
class ZwaveEvent(Event):
[docs]
def __init__(self, device: Optional[str] = None, *args, **kwargs):
super().__init__(*args, device=device, **kwargs)
[docs]
class ZwaveNetworkReadyEvent(ZwaveEvent):
"""
Triggered when the network started on a Z-Wave adapter becomes ready.
"""
[docs]
def __init__(
self,
ozw_library_version: str,
python_library_version: str,
zwave_library: str,
node_id: int,
node_version: str,
home_id: int,
nodes_count: int,
device: Optional[str] = None,
*args,
**kwargs
):
super().__init__(
*args,
device=device,
ozw_library_version=ozw_library_version,
python_library_version=python_library_version,
zwave_library=zwave_library,
home_id=home_id,
node_id=node_id,
node_version=node_version,
nodes_count=nodes_count,
**kwargs
)
[docs]
class ZwaveNetworkStoppedEvent(ZwaveEvent):
"""
Triggered when a Z-Wave network is stopped.
"""
[docs]
class ZwaveNetworkErrorEvent(ZwaveEvent):
"""
Triggered when an error occurs on the Z-Wave network.
"""
[docs]
class ZwaveNetworkResetEvent(ZwaveEvent):
"""
Triggered when a Z-Wave network is reset.
"""
[docs]
class ZwaveNodeEvent(ZwaveEvent):
"""
Generic Z-Wave node event class.
"""
[docs]
def __init__(self, node: Dict[str, Any], *args, **kwargs):
super().__init__(*args, node=node, **kwargs)
[docs]
class ZwaveNodeAddedEvent(ZwaveNodeEvent):
"""
Triggered when a node is added to the network.
"""
[docs]
class ZwaveNodeRemovedEvent(ZwaveNodeEvent):
"""
Triggered when a node is removed from the network.
"""
[docs]
class ZwaveNodeRenamedEvent(ZwaveNodeEvent):
"""
Triggered when a node is renamed.
"""
[docs]
class ZwaveNodeReadyEvent(ZwaveNodeEvent):
"""
Triggered when a node is ready.
"""
[docs]
class ZwaveNodeAsleepEvent(ZwaveNodeEvent):
"""
Triggered when a node goes in sleep mode.
"""
[docs]
class ZwaveNodeAwakeEvent(ZwaveNodeEvent):
"""
Triggered when a node goes back into awake mode.
"""
[docs]
class ZwaveNodeGroupEvent(ZwaveNodeEvent):
"""
Triggered when a node is associated/de-associated to a group.
"""
[docs]
def __init__(self, group_index: Optional[int] = None, *args, **kwargs):
# ZwaveNodeGroupEvent can be quite verbose, so we only report them if
# debug logging is enabled
kwargs['logging_level'] = logging.DEBUG
super().__init__(*args, group_index=group_index, **kwargs)
[docs]
class ZwaveNodeSceneEvent(ZwaveNodeEvent):
"""
Triggered when a scene is activated on a node.
"""
[docs]
def __init__(self, scene_id: int, *args, **kwargs):
super().__init__(*args, scene_id=scene_id, **kwargs)
[docs]
class ZwaveNodePollingEnabledEvent(ZwaveNodeEvent):
"""
Triggered when the polling of a node is successfully turned on.
"""
[docs]
class ZwaveNodePollingDisabledEvent(ZwaveNodeEvent):
"""
Triggered when the polling of a node is successfully turned off.
"""
[docs]
class ZwaveValueEvent(ZwaveEvent):
"""
Abstract class for Z-Wave value events.
"""
[docs]
def __init__(self, node: Dict[str, Any], value: Dict[str, Any], *args, **kwargs):
# ZwaveValueEvent can be quite verbose, so we only report them if debug
# logging is enabled
kwargs['logging_level'] = logging.DEBUG
super().__init__(*args, node=node, value=value, **kwargs)
[docs]
class ZwaveValueAddedEvent(ZwaveValueEvent):
"""
Triggered when a value is added to a node on the network.
"""
[docs]
class ZwaveValueChangedEvent(ZwaveValueEvent):
"""
Triggered when a value of a node on the network changes.
"""
[docs]
class ZwaveValueRefreshedEvent(ZwaveValueEvent):
"""
Triggered when a value of a node on the network is refreshed.
"""
[docs]
class ZwaveValueRemovedEvent(ZwaveValueEvent):
"""
Triggered when a value of a node on the network is removed.
"""
[docs]
class ZwaveNodeQueryCompletedEvent(ZwaveEvent):
"""
Triggered when all the nodes on the network have been queried.
"""
[docs]
class ZwaveCommandEvent(ZwaveEvent):
"""
Triggered when a command is received on the network.
"""
[docs]
def __init__(
self,
state: str,
state_description: str,
error: Optional[str] = None,
error_description: Optional[str] = None,
node: Optional[Dict[str, Any]] = None,
*args,
**kwargs
):
super().__init__(
*args,
state=state,
state_description=state_description,
error=error,
error_description=error_description,
node=node,
**kwargs
)
[docs]
class ZwaveCommandWaitingEvent(ZwaveCommandEvent):
"""
Triggered when a command is waiting for a message to proceed.
"""
# vim:sw=4:ts=4:et: