test_qoto_03_sprinkler.py 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. """Tests for the Quto 03 Sprinkler."""
  2. from homeassistant.components.binary_sensor import BinarySensorDeviceClass
  3. from homeassistant.components.number import NumberDeviceClass
  4. from homeassistant.components.valve import ValveDeviceClass, ValveEntityFeature
  5. from homeassistant.const import UnitOfTime
  6. from ..const import QOTO_SPRINKLER_PAYLOAD
  7. from ..helpers import assert_device_properties_set
  8. from ..mixins.binary_sensor import BasicBinarySensorTests
  9. from ..mixins.number import MultiNumberTests
  10. from ..mixins.sensor import MultiSensorTests
  11. from .base_device_tests import TuyaDeviceTestCase
  12. TARGET_DPS = "102"
  13. CURRENT_DPS = "103"
  14. COUNTDOWN_DPS = "104"
  15. TIMER_DPS = "105"
  16. ERROR_DPS = "108"
  17. class TestQotoSprinkler(
  18. BasicBinarySensorTests,
  19. MultiNumberTests,
  20. MultiSensorTests,
  21. TuyaDeviceTestCase,
  22. ):
  23. __test__ = True
  24. def setUp(self):
  25. self.setUpForConfig("qoto_03_sprinkler.yaml", QOTO_SPRINKLER_PAYLOAD)
  26. self.subject = self.entities.get("valve_water")
  27. self.setUpBasicBinarySensor(
  28. ERROR_DPS,
  29. self.entities.get("binary_sensor_problem"),
  30. device_class=BinarySensorDeviceClass.PROBLEM,
  31. testdata=(1, 0),
  32. )
  33. self.setUpMultiNumber(
  34. [
  35. {
  36. "name": "number_timer",
  37. "dps": TIMER_DPS,
  38. "max": 86399,
  39. "device_class": NumberDeviceClass.DURATION,
  40. "unit": UnitOfTime.SECONDS,
  41. },
  42. ]
  43. )
  44. self.setUpMultiSensors(
  45. [
  46. {
  47. "name": "sensor_open",
  48. "dps": CURRENT_DPS,
  49. "unit": "%",
  50. },
  51. {
  52. "name": "sensor_time_remaining",
  53. "dps": COUNTDOWN_DPS,
  54. "device_class": "duration",
  55. "unit": "s",
  56. },
  57. ]
  58. )
  59. self.mark_secondary(
  60. [
  61. "number",
  62. "binary_sensor_problem",
  63. "number_timer",
  64. "sensor_open",
  65. "sensor_time_remaining",
  66. "time_timer",
  67. ]
  68. )
  69. def test_device_class_is_water(self):
  70. self.assertEqual(self.subject.device_class, ValveDeviceClass.WATER)
  71. def test_supported_features(self):
  72. self.assertEqual(
  73. self.subject.supported_features,
  74. ValveEntityFeature.OPEN
  75. | ValveEntityFeature.CLOSE
  76. | ValveEntityFeature.SET_POSITION,
  77. )
  78. def test_is_closed(self):
  79. self.dps[TARGET_DPS] = 100
  80. self.assertFalse(self.subject.is_closed)
  81. self.dps[TARGET_DPS] = 50
  82. self.assertFalse(self.subject.is_closed)
  83. self.dps[TARGET_DPS] = 0
  84. self.assertTrue(self.subject.is_closed)
  85. def test_current_position(self):
  86. self.dps[TARGET_DPS] = 100
  87. self.assertEqual(self.subject.current_position, 100)
  88. self.dps[TARGET_DPS] = 50
  89. self.assertEqual(self.subject.current_position, 50)
  90. self.dps[TARGET_DPS] = 0
  91. self.assertEqual(self.subject.current_position, 0)
  92. async def test_open_valve(self):
  93. async with assert_device_properties_set(
  94. self.subject._device,
  95. {TARGET_DPS: 100},
  96. ):
  97. await self.subject.async_open_valve()
  98. async def test_close_valve(self):
  99. async with assert_device_properties_set(
  100. self.subject._device,
  101. {TARGET_DPS: 0},
  102. ):
  103. await self.subject.async_close_valve()
  104. async def test_set_valve_position(self):
  105. async with assert_device_properties_set(
  106. self.subject._device,
  107. {TARGET_DPS: 50},
  108. ):
  109. await self.subject.async_set_valve_position(50)
  110. def test_basic_bsensor_extra_state_attributes(self):
  111. self.dps[ERROR_DPS] = 2
  112. self.assertDictEqual(
  113. self.basicBSensor.extra_state_attributes,
  114. {"fault_code": 2},
  115. )