test_lock.py 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. import pytest
  2. from switchbot import SwitchbotModel
  3. from switchbot.devices import lock
  4. from .test_adv_parser import generate_ble_device
  5. def create_device_for_command_testing(model: str):
  6. ble_device = generate_ble_device("aa:bb:cc:dd:ee:ff", "any")
  7. return lock.SwitchbotLock(
  8. ble_device, "ff", "ffffffffffffffffffffffffffffffff", model=model
  9. )
  10. @pytest.mark.parametrize(
  11. "model",
  12. [
  13. SwitchbotModel.LOCK,
  14. SwitchbotModel.LOCK_LITE,
  15. SwitchbotModel.LOCK_PRO,
  16. SwitchbotModel.LOCK_ULTRA,
  17. ],
  18. )
  19. def test_lock_init(model: str):
  20. """Test the initialization of the lock device."""
  21. device = create_device_for_command_testing(model)
  22. assert device._model == model
  23. @pytest.mark.parametrize(
  24. "model",
  25. [
  26. SwitchbotModel.AIR_PURIFIER,
  27. ],
  28. )
  29. def test_lock_init_with_invalid_model(model: str):
  30. """Test that initializing with an invalid model raises ValueError."""
  31. with pytest.raises(
  32. ValueError, match="initializing SwitchbotLock with a non-lock model"
  33. ):
  34. create_device_for_command_testing(model)