test_qoto_03_sprinkler.py 3.5 KB

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