示例#1
0
 def _encode_characteristic(
         gadget: Gadget,
         characteristic_type: CharacteristicIdentifier) -> dict:
     gadget_characteristic = gadget.get_characteristic(characteristic_type)
     value_range = gadget_characteristic.get_max(
     ) - gadget_characteristic.get_min()
     min_step = value_range // gadget_characteristic.get_steps()
     return {
         "minValue": gadget_characteristic.get_min(),
         "maxValue": gadget_characteristic.get_max(),
         "minStep": min_step
     }
示例#2
0
    def _update_characteristic(self, gadget: Gadget,
                               characteristic: CharacteristicIdentifier):
        """
        Updates a specific characteristic on from the gadget on the remote storage

        :param gadget: Gadget to get characteristic information from
        :param characteristic: Characteristic to update
        :return: None
        :raises CharacteristicParsingError: If selected characteristic could not be parsed correctly
        """
        characteristic_value = gadget.get_characteristic(
            characteristic).get_true_value()
        characteristic_str = HomebridgeCharacteristicTranslator.type_to_string(
            characteristic)
        self._network_connector.update_characteristic(gadget.get_name(),
                                                      characteristic_str,
                                                      characteristic_value)
    def receive_gadget_update(self, gadget: Gadget):
        found_gadget = self.get_gadget(gadget.get_name())
        if found_gadget is None:
            self._logger.error(
                f"Received update data for unknown gadget '{gadget.get_name()}'"
            )
            return
        changed_characteristics = []
        for c in found_gadget.get_characteristics():
            buf_characteristic = gadget.get_characteristic(c.get_type())
            if buf_characteristic is None:
                continue
            if c.get_step_value() != buf_characteristic.get_step_value():
                c.set_step_value(buf_characteristic.get_step_value())
                changed_characteristics.append(c)

        if changed_characteristics:
            buf_gadget = AnyGadget(gadget.get_name(), "any",
                                   changed_characteristics)
            self._publish_gadget_update(buf_gadget)
def test_gadget_publisher_homebridge_network(
        publisher_network: GadgetPublisherHomeBridge, gadget: Gadget):
    with pytest.raises(GadgetDeletionError):
        publisher_network.remove_gadget(gadget.get_name())

    publisher_network.create_gadget(gadget)

    with pytest.raises(GadgetCreationError):
        publisher_network.create_gadget(gadget)

    publisher_network.remove_gadget(gadget.get_name())

    fan_speed = gadget.get_characteristic(CharacteristicIdentifier.fan_speed)
    fan_speed.set_step_value(2)

    publisher_network.receive_gadget(gadget)

    fan_speed.set_step_value(3)

    publisher_network.receive_gadget(gadget)

    publisher_network.remove_gadget(gadget.get_name())