1 """Representation of an EnOcean dongle."""
5 from os.path
import basename, normpath
7 from enocean.communicators
import SerialCommunicator
8 from enocean.protocol.packet
import RadioPacket
13 from .const
import SIGNAL_RECEIVE_MESSAGE, SIGNAL_SEND_MESSAGE
15 _LOGGER = logging.getLogger(__name__)
19 """Representation of an EnOcean dongle.
21 The dongle is responsible for receiving the ENOcean frames,
22 creating devices if needed, and dispatching messages to platforms.
26 """Initialize the EnOcean dongle."""
29 port=serial_path, callback=self.
callbackcallback
32 self.
identifieridentifier = basename(normpath(serial_path))
37 """Finish the setup of the bridge and supported platforms."""
44 """Disconnect callbacks established at init time."""
50 """Send a command through the EnOcean dongle."""
54 """Handle EnOcean device's callback.
56 This is the callback function called by python-enocan whenever there
57 is an incoming packet.
60 if isinstance(packet, RadioPacket):
61 _LOGGER.debug(
"Received radio packet: %s", packet)
66 """Return a list of candidate paths for USB ENOcean dongles.
68 This method is currently a bit simplistic, it may need to be
69 improved to support more configurations and OS.
71 globs_to_test = [
"/dev/tty*FTOA2PV*",
"/dev/serial/by-id/*EnOcean*"]
73 for current_glob
in globs_to_test:
74 found_paths.extend(glob.glob(current_glob))
80 """Return True if the provided path points to a valid serial port, False otherwise."""
84 SerialCommunicator(port=path)
85 except serial.SerialException
as exception:
86 _LOGGER.warning(
"Dongle path %s is invalid: %s", path,
str(exception))
def _send_message_callback(self, command)
dispatcher_disconnect_handle
def __init__(self, hass, serial_path)
def callback(self, packet)
def validate_path(str path)
Callable[[], None] async_dispatcher_connect(HomeAssistant hass, str signal, Callable[..., Any] target)
None dispatcher_send(HomeAssistant hass, str signal, *Any args)