test_qoto_03_sprinkler.py 3.6 KB

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