示例#1
0
文件: ds18x20.py 项目: Jockra/mqttany
 def get_node(self) -> BusNode:
     node = super().get_node()
     node.add_property(
         "temperature",
         BusProperty(name="Temperature",
                     datatype=DataType.FLOAT,
                     unit=f"°{self._unit}"),
     )
     node.add_property("unit", BusProperty(name="Unit"))
     return node
示例#2
0
 def get_node(self) -> BusNode:
     """
     Returns a ``BusNode`` representing this array.
     """
     node = super().get_node()
     node.add_property("universe", BusProperty(name="Universe"))
     node.add_property("mode", BusProperty(name="Operating Mode"))
     if self._address is not None:
         node.add_property("address", BusProperty(name="Client Address"))
     if self._sync is not None:
         node.add_property("sync", BusProperty(name="Sync Universe"))
     return node
示例#3
0
文件: rpi.py 项目: Jockra/mqttany
 def get_node(self) -> BusNode:
     """
     Returns a ``BusNode`` representing this array.
     """
     node = super().get_node()
     node.add_property("gpio", BusProperty(name="GPIO Pin", datatype=DataType.INT))
     node.add_property("chip", BusProperty(name="LED Chip"))
     node.add_property(
         "frequency",
         BusProperty(name="Frequency", datatype=DataType.INT, unit="kHz"),
     )
     node.add_property(
         "invert", BusProperty(name="Signal Invert", datatype=DataType.BOOL)
     )
     return node
示例#4
0
 def get_node(self) -> BusNode:
     """
     Returns a ``BusNode`` representing this array.
     """
     return BusNode(
         name=self._name,
         type="LED Array",
         properties={
             "animation": BusProperty(
                 name="Animation", settable=True, callback="anim_message"
             ),
             "count": BusProperty(name="LED Count", datatype=DataType.INT),
             "leds-per-pixel": BusProperty(
                 name="LEDs per Pixel", datatype=DataType.INT
             ),
             "fps": BusProperty(name="Frames per second", datatype=DataType.INT),
         },
     )
示例#5
0
 def get_node(self) -> BusNode:
     """
     Subclasses MUST override and ``super()`` this method.
     Returns a ``BusNode`` representing the device and all its properties.
     """
     return BusNode(
         name=self.name,
         type=self.device,
         properties={"address": BusProperty(name="Address")},
     )
示例#6
0
文件: core.py 项目: Jockra/mqttany
def load(config_raw: t.Dict[str, t.Any]) -> bool:
    """
    This function runs on the main process after the module is imported. It should parse
    and validate the configuration and create any dynamic nodes or properties. Do not start
    any threads or long running tasks here, they should go in the ``start`` function.
    Limit memory usage here as much as possible.
    """
    config_data = parse_config(config_raw, CONF_OPTIONS, log)
    del config_raw
    if config_data:
        log.debug("Config loaded successfully")
        CONFIG.update(config_data)
        del config_data
        # verify config

        # generate dynamic nodes
        nodes["my-node"] = BusNode(
            name="My Node",
            type="module",
            properties={
                # This property is a string type that this module can publish to
                "my-property":
                BusProperty(name="Read-Only Property"),
                # This property is an integer that outside systems can set
                "my-writable-property":
                BusProperty(
                    name="Writable Property",
                    datatype=DataType.INT,
                    settable=True,
                    # This function will be called when a message arrives. Topic/path
                    # matching depends on the communication module.
                    # Must be a string, object references do not cross process borders
                    # Don't forget to import it in the package '__init__.py' as it will
                    # be called by name as 'interface_pkg_template.message_callback'
                    callback="message_callback",
                ),
            },
        )

        return True
    else:
        log.error("Error loading config")
        return False
示例#7
0
 def get_node(self) -> BusNode:
     node = super().get_node()
     node.add_property(
         "poll-all",
         BusProperty(name="Poll All Pins", settable=True, callback="device_message"),
     )
     node.add_property(
         "pulse", BusProperty(name="Pulse", settable=True, callback="device_message")
     )
     for pin in [pin for pin in self._pins if pin is not None]:
         node.add_property(
             pin.id,
             BusProperty(
                 name=pin.name,
                 settable=pin.direction == Direction.OUTPUT,
                 callback="device_message",
             ),
         )
         node.add_property(str(pin.pin), node.properties[pin.id])
     return node
示例#8
0
                "selection": {}
            },
        },
    ),
])

log = logger.get_logger("gpio")
CONFIG: t.Dict[str, t.Any] = {}

publish_queue: "mproc.Queue[BusMessage]" = None  # type: ignore
nodes: t.Dict[str, BusNode] = {
    "gpio":
    BusNode(
        name="GPIO",
        type="Module",
        properties={
            "poll-all":
            BusProperty(name="Poll All Pins",
                        settable=True,
                        callback="poll_message"),
            "polling-interval":
            BusProperty(name="Polling Interval",
                        datatype=DataType.FLOAT,
                        unit="s"),
            # from pin.digital
            "pulse":
            BusProperty(name="Pulse", settable=True, callback="pulse_message"),
        },
    )
}
示例#9
0
    ]
)

log = logger.get_logger("i2c")
CONFIG: t.Dict[str, t.Any] = {}

publish_queue: "mproc.Queue[BusMessage]" = None  # type: ignore
nodes: t.Dict[str, BusNode] = {
    "i2c":
    BusNode(
        name="I2C",
        type="Module",
        properties={
            "poll-all":
            BusProperty(name="Poll All",
                        settable=True,
                        callback="poll_message"),
            "polling-interval":
            BusProperty(name="Polling Interval",
                        datatype=DataType.INT,
                        unit="s"),
        },
    )
}


def validateAddress(address: t.Any) -> t.Union[int, None]:
    """
    Validates I2C address.
    Returns ``None`` if address is invalid.
    """
示例#10
0
 def get_property(self) -> BusProperty:
     return BusProperty(
         name=self.name,
         settable=self._mode == PinMode.OUTPUT,
         callback="pin_message",
     )
示例#11
0
文件: xset.py 项目: Jockra/mqttany
        "type": list
    }),
])

log = logger.get_logger("xset")
CONFIG: t.Dict[str, t.Any] = {}

publish_queue: "mproc.Queue[BusMessage]" = None  # type: ignore
subscribe_queue: "mproc.Queue[BusMessage]" = None  # type: ignore
nodes: t.Dict[str, BusNode] = {
    "xset":
    BusNode(
        name="XSET",
        type="Module",
        properties={
            "command": BusProperty(name="XSET Command", settable=True),
            "stdout": BusProperty(name="stdout"),
            "stderr": BusProperty(name="stderr"),
        },
    )
}


def load(config_raw: t.Dict[str, t.Any] = {}) -> bool:
    """
    Initializes the module
    """
    config_data = parse_config(config_raw, CONF_OPTIONS, log)
    del config_raw
    if config_data:
        log.debug("Config loaded")
示例#12
0
文件: counter.py 项目: Jockra/mqttany
 def get_property(self) -> BusProperty:
     return BusProperty(
         name=self.name,
         datatype=DataType.STR
         if self._function == Function.RAW else DataType.FLOAT,
     )