test_qoto_03_sprinkler.py 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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 PERCENTAGE, 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",
  37. "dps": TARGET_DPS,
  38. "max": 100,
  39. "step": 5,
  40. "unit": PERCENTAGE,
  41. },
  42. {
  43. "name": "number_timer",
  44. "dps": TIMER_DPS,
  45. "max": 86399,
  46. "device_class": NumberDeviceClass.DURATION,
  47. "unit": UnitOfTime.SECONDS,
  48. },
  49. ]
  50. )
  51. self.setUpMultiSensors(
  52. [
  53. {
  54. "name": "sensor_open",
  55. "dps": CURRENT_DPS,
  56. "unit": "%",
  57. },
  58. {
  59. "name": "sensor_time_remaining",
  60. "dps": COUNTDOWN_DPS,
  61. "device_class": "duration",
  62. "unit": "s",
  63. },
  64. ]
  65. )
  66. self.mark_secondary(
  67. [
  68. "number",
  69. "binary_sensor_problem",
  70. "number_timer",
  71. "sensor_open",
  72. "sensor_time_remaining",
  73. ]
  74. )
  75. def test_device_class_is_water(self):
  76. self.assertEqual(self.subject.device_class, ValveDeviceClass.WATER)
  77. def test_supported_features(self):
  78. self.assertEqual(
  79. self.subject.supported_features,
  80. ValveEntityFeature.OPEN
  81. | ValveEntityFeature.CLOSE
  82. | ValveEntityFeature.SET_POSITION,
  83. )
  84. def test_is_closed(self):
  85. self.dps[TARGET_DPS] = 100
  86. self.assertFalse(self.subject.is_closed)
  87. self.dps[TARGET_DPS] = 50
  88. self.assertFalse(self.subject.is_closed)
  89. self.dps[TARGET_DPS] = 0
  90. self.assertTrue(self.subject.is_closed)
  91. def test_current_position(self):
  92. self.dps[TARGET_DPS] = 100
  93. self.assertEqual(self.subject.current_position, 100)
  94. self.dps[TARGET_DPS] = 50
  95. self.assertEqual(self.subject.current_position, 50)
  96. self.dps[TARGET_DPS] = 0
  97. self.assertEqual(self.subject.current_position, 0)
  98. async def test_open_valve(self):
  99. async with assert_device_properties_set(
  100. self.subject._device,
  101. {TARGET_DPS: 100},
  102. ):
  103. await self.subject.async_open_valve()
  104. async def test_close_valve(self):
  105. async with assert_device_properties_set(
  106. self.subject._device,
  107. {TARGET_DPS: 0},
  108. ):
  109. await self.subject.async_close_valve()
  110. async def test_set_valve_position(self):
  111. async with assert_device_properties_set(
  112. self.subject._device,
  113. {TARGET_DPS: 50},
  114. ):
  115. await self.subject.async_set_valve_position(50)
  116. def test_basic_bsensor_extra_state_attributes(self):
  117. self.dps[ERROR_DPS] = 2
  118. self.assertDictEqual(
  119. self.basicBSensor.extra_state_attributes,
  120. {"fault_code": 2},
  121. )