test_qoto_03_sprinkler.py 3.5 KB

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