Exemple #1
0
    async def set_target_temperature_setpoint_shift(self, target_temperature):
        """Set target temperature via setpoint_shift group address."""
        temperature_delta = target_temperature-self.target_temperature.value
        setpoint_shift_delta = int(temperature_delta/self.setpoint_shift_step)
        setpoint_shift = self.setpoint_shift.value + setpoint_shift_delta

        if setpoint_shift > self.setpoint_shift_max:
            raise DeviceIllegalValue("setpoint_shift_max exceeded", setpoint_shift)
        elif setpoint_shift < self.setpoint_shift_min:
            raise DeviceIllegalValue("setpoint_shift_min exceeded", setpoint_shift)

        await self.setpoint_shift.set(setpoint_shift)
Exemple #2
0
 def test_device_illegal_value_exception(self):
     """Test string representation of DeviceIllegalValue exception."""
     exception = DeviceIllegalValue(value=12, description="Fnord exceeded")
     self.assertEqual(
         str(exception),
         '<DeviceIllegalValue description="12" value="Fnord exceeded" />',
     )
Exemple #3
0
 async def set_operation_mode(self, operation_mode):
     """Set the operation mode of a thermostat. Send new operation_mode to BUS and update internal state."""
     if not self.supports_operation_mode:
         raise DeviceIllegalValue("operation mode not supported",
                                  operation_mode)
     if self.group_address_operation_mode is not None:
         await self.send(self.group_address_operation_mode,
                         DPTArray(DPTHVACMode.to_knx(operation_mode)))
     if self.group_address_operation_mode_protection is not None:
         protection_mode = operation_mode == HVACOperationMode.FROST_PROTECTION
         await self.send(self.group_address_operation_mode_protection,
                         DPTBinary(protection_mode))
     if self.group_address_operation_mode_night is not None:
         night_mode = operation_mode == HVACOperationMode.NIGHT
         await self.send(self.group_address_operation_mode_night,
                         DPTBinary(night_mode))
     if self.group_address_operation_mode_comfort is not None:
         comfort_mode = operation_mode == HVACOperationMode.COMFORT
         await self.send(self.group_address_operation_mode_comfort,
                         DPTBinary(comfort_mode))
     if self.group_address_controller_status is not None:
         await self.send(
             self.group_address_controller_status,
             DPTArray(DPTControllerStatus.to_knx(operation_mode)))
     if self.group_address_controller_mode is not None:
         await self.send(self.group_address_controller_mode,
                         DPTArray(DPTHVACContrMode.to_knx(operation_mode)))
     await self._set_internal_operation_mode(operation_mode)
Exemple #4
0
    async def set_controller_mode(self, controller_mode):
        """Set the controller mode of a thermostat. Send new controller mode to the bus and update internal state."""
        if (not self.supports_controller_mode
                or controller_mode not in self._controller_modes):
            raise DeviceIllegalValue("controller (HVAC) mode not supported",
                                     controller_mode)

        for rv in self._iter_controller_remote_values():
            if rv.writable and controller_mode in rv.supported_operation_modes(
            ):
                await rv.set(controller_mode)

        await self._set_internal_controller_mode(controller_mode)
Exemple #5
0
    async def set_fan_mode(self, fan_mode):
        """Set the fan mode of a thermostat. Send new fan_mode to BUS and update internal state."""
        if not self.supports_fan_mode:
            raise DeviceIllegalValue("fan mode not supported", fan_mode)

        if fan_mode == 'Low':
            await self.fan_mode.set(1)
        if fan_mode == 'Medium':
            await self.fan_mode.set(2)
        if fan_mode == 'High':
            await self.fan_mode.set(3)
        if fan_mode == 'Auto':
            await self.fan_mode.set(4)
Exemple #6
0
    async def set_operation_mode(self, operation_mode):
        """Set the operation mode of a thermostat. Send new operation_mode to BUS and update internal state."""
        if (
            not self.supports_operation_mode
            or operation_mode not in self.operation_modes_
        ):
            raise DeviceIllegalValue("operation mode not supported", operation_mode)

        for rv in self._iter_remote_values():
            if rv.writable and operation_mode in rv.supported_operation_modes():
                await rv.set(operation_mode)

        await self._set_internal_operation_mode(operation_mode)
Exemple #7
0
    async def set_operation_mode(self, operation_mode):
        """Set the operation mode of a thermostat. Send new operation_mode to BUS and update internal state."""
        if not self.supports_operation_mode:
            raise DeviceIllegalValue("operation mode not supported",
                                     operation_mode)

        if operation_mode == 'Cool':
            await self.operation_mode.set(1)
        if operation_mode == 'Heat':
            await self.operation_mode.set(4)
        if operation_mode == 'Fan':
            await self.operation_mode.set(3)
        if operation_mode == 'Dry':
            await self.operation_mode.set(2)
Exemple #8
0
    async def set_controller_mode(self,
                                  controller_mode: HVACControllerMode) -> None:
        """Set the controller mode of a thermostat. Send new controller mode to the bus and update internal state."""
        if (not self.supports_controller_mode
                or controller_mode not in self._controller_modes):
            raise DeviceIllegalValue("controller (HVAC) mode not supported",
                                     str(controller_mode))

        rv_controller: RemoteValueClimateModeBase[Any, HVACControllerMode]
        for rv_controller in self._iter_controller_remote_values():
            if (rv_controller.writable and controller_mode
                    in rv_controller.supported_operation_modes()):
                await rv_controller.set(controller_mode)

        await self._set_internal_controller_mode(controller_mode)
Exemple #9
0
    async def set_operation_mode(self,
                                 operation_mode: HVACOperationMode) -> None:
        """Set the operation mode of a thermostat. Send new operation_mode to BUS and update internal state."""
        if (not self.supports_operation_mode
                or operation_mode not in self._operation_modes):
            raise DeviceIllegalValue("operation (preset) mode not supported",
                                     str(operation_mode))

        rv_operation: RemoteValueClimateModeBase[Any, HVACOperationMode]
        for rv_operation in self._iter_operation_remote_values():
            if (rv_operation.writable and operation_mode
                    in rv_operation.supported_operation_modes()):
                await rv_operation.set(operation_mode)

        await self._set_internal_operation_mode(operation_mode)
Exemple #10
0
            CouldNotParseAddress(123),
            CouldNotParseAddress(123),
            CouldNotParseAddress(321),
        ),
        (
            CouldNotParseKNXIP("desc1"),
            CouldNotParseKNXIP("desc1"),
            CouldNotParseKNXIP("desc2"),
        ),
        (
            CouldNotParseTelegram("desc", arg1=1, arg2=2),
            CouldNotParseTelegram("desc", arg1=1, arg2=2),
            CouldNotParseTelegram("desc", arg1=2, arg2=1),
        ),
        (
            DeviceIllegalValue("value1", "desc"),
            DeviceIllegalValue("value1", "desc"),
            DeviceIllegalValue("value1", "desc2"),
        ),
        (
            XKNXException("desc1"),
            XKNXException("desc1"),
            XKNXException("desc2"),
        ),
    ],
)
def test_exceptions(base, equal, diff):
    """Test hashability and repr of exceptions."""
    assert hash(base) == hash(equal)
    assert hash(base) != hash(diff)
    assert base == equal