def off(self, botengine, reliably=False):
        """
        Turn off
        :param botengine: BotEngine environment
        :param reliably: True to send the command reliably (default is False)
        """
        if not self.can_control:
            return False

        if reliably:
            cancel_reliable_command(botengine, self.device_id, SmartplugDevice.MEASUREMENT_NAME_STATUS)
            send_command_reliably(botengine, self.device_id, SmartplugDevice.MEASUREMENT_NAME_STATUS, "0")

        else:
            botengine.send_command(self.device_id, SmartplugDevice.MEASUREMENT_NAME_STATUS, "0") # TODO this should be able to say the keyword False, but that doesn't work. Needs a server fix.

        return True
    def on(self, botengine, reliably=False):
        """
        Turn on
        :param botengine: BotEngine environment
        :param reliably: True to send the command reliably (default is False)
        """
        if not self.can_control:
            return False

        if reliably:
            cancel_reliable_command(botengine, self.device_id, SmartplugDevice.MEASUREMENT_NAME_STATUS)
            send_command_reliably(botengine, self.device_id, SmartplugDevice.MEASUREMENT_NAME_STATUS, "1")

        else:
            botengine.send_command(self.device_id, SmartplugDevice.MEASUREMENT_NAME_STATUS, "1") # This does work with the keyword True.

        return True
Exemple #3
0
    def set_heating_setpoint(self, botengine, setpoint_celsius, reliably=True):
        """
        Set the heating set-point
        :param botengine: BotEngine environmnet
        :param setpoint_celsius: Temperature in Celsius
        :param reliably: True to keep retrying to get the command through
        """
        setpoint_celsius = float(setpoint_celsius)
        if self.is_temperature_different(
                setpoint_celsius,
                self.measurements[ThermostatDevice.
                                  MEASUREMENT_NAME_HEATING_SETPOINT_C][0][0]):
            botengine.get_logger().info(
                "\t\t[" + self.device_id + "] (" + self.description +
                "): Set heating setpoint from " + str(self.measurements[
                    ThermostatDevice.MEASUREMENT_NAME_HEATING_SETPOINT_C][0]
                                                      [0]) + " to " +
                str("%.1f" % setpoint_celsius))
            self.last_heating_setpoint_command = (setpoint_celsius,
                                                  botengine.get_timestamp(),
                                                  False)

            if reliably:
                send_command_reliably(
                    botengine, self.device_id,
                    ThermostatDevice.MEASUREMENT_NAME_HEATING_SETPOINT_C,
                    float(str("%.1f" % setpoint_celsius)))
            else:
                botengine.send_command(
                    self.device_id,
                    ThermostatDevice.MEASUREMENT_NAME_HEATING_SETPOINT_C,
                    float(str("%.1f" % setpoint_celsius)))

            # Because Dmitry says we might see specific errors better if we issue commands one-by-one, especially to cloud-connected thermostats.
            botengine.flush_commands()

        else:
            botengine.get_logger().info(
                "\t\t{}: Set heating setpoint {} is the same as the current setpoint, skipping."
                .format(self.device_id, str("%.1f" % setpoint_celsius)))
            botengine.cancel_command(
                self.device_id,
                ThermostatDevice.MEASUREMENT_NAME_HEATING_SETPOINT_C)
            cancel_reliable_command(
                botengine, self.device_id,
                ThermostatDevice.MEASUREMENT_NAME_HEATING_SETPOINT_C)
Exemple #4
0
    def off(self, botengine, reliably=False):
        """
        Turn off
        :param botengine: BotEngine environment
        :param reliably: True to send the command reliably (default is False)
        """
        if not self.can_control:
            return False

        if reliably:
            cancel_reliable_command(botengine, self.device_id,
                                    SmartplugDevice.MEASUREMENT_NAME_STATUS)
            send_command_reliably(botengine, self.device_id,
                                  SmartplugDevice.MEASUREMENT_NAME_STATUS, "0")

        else:
            botengine.send_command(
                self.device_id, SmartplugDevice.MEASUREMENT_NAME_STATUS, "0"
            )  # TODO this should be able to say the keyword False, but that doesn't work. Needs a server fix.

        return True
Exemple #5
0
    def on(self, botengine, reliably=False):
        """
        Turn on
        :param botengine: BotEngine environment
        :param reliably: True to send the command reliably (default is False)
        """
        if not self.can_control:
            return False

        if reliably:
            cancel_reliable_command(botengine, self.device_id,
                                    SmartplugDevice.MEASUREMENT_NAME_STATUS)
            send_command_reliably(botengine, self.device_id,
                                  SmartplugDevice.MEASUREMENT_NAME_STATUS, "1")

        else:
            botengine.send_command(
                self.device_id, SmartplugDevice.MEASUREMENT_NAME_STATUS,
                "1")  # This does work with the keyword True.

        return True
Exemple #6
0
    def set_system_mode(self, botengine, system_mode, reliably=True):
        """
        Set the system mode
        :param botengine:
        :param system_mode:
        :param reliably: True to keep retrying to get the command through
        :return:
        """
        botengine.get_logger().info(
            "\t\t[" + self.device_id + "]: Set system mode to {}".format(
                self.thermostat_mode_to_string(system_mode)))
        self.last_system_mode_command = (system_mode,
                                         botengine.get_timestamp(), False)
        if reliably:
            send_command_reliably(
                botengine, self.device_id,
                ThermostatDevice.MEASUREMENT_NAME_SYSTEM_MODE, system_mode)
        else:
            botengine.send_command(
                self.device_id, ThermostatDevice.MEASUREMENT_NAME_SYSTEM_MODE,
                system_mode)

        # Because Dmitry says we might see specific errors better if we issue commands one-by-one, especially to cloud-connected thermostats.
        botengine.flush_commands()