test_orion_outdoor_siren.py 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. from homeassistant.components.binary_sensor import BinarySensorDeviceClass
  2. from homeassistant.components.sensor import SensorDeviceClass
  3. from homeassistant.components.siren import SirenEntityFeature
  4. from homeassistant.const import PERCENTAGE
  5. from ..const import ORION_SIREN_PAYLOAD
  6. from ..helpers import assert_device_properties_set
  7. from ..mixins.binary_sensor import MultiBinarySensorTests
  8. from ..mixins.sensor import BasicSensorTests
  9. from .base_device_tests import TuyaDeviceTestCase
  10. TONE_DP = "1"
  11. VOLUME_DP = "5"
  12. CHARGING_DP = "6"
  13. DURATION_DP = "7"
  14. BATTERY_DP = "15"
  15. TAMPER_DP = "20"
  16. class TestOrionSiren(MultiBinarySensorTests, BasicSensorTests, TuyaDeviceTestCase):
  17. __test__ = True
  18. def setUp(self):
  19. self.setUpForConfig("orion_outdoor_siren.yaml", ORION_SIREN_PAYLOAD)
  20. self.subject = self.entities.get("siren")
  21. self.setUpMultiBinarySensors(
  22. [
  23. {
  24. "dps": CHARGING_DP,
  25. "name": "binary_sensor_charging",
  26. "device_class": BinarySensorDeviceClass.BATTERY_CHARGING,
  27. },
  28. {
  29. "dps": TAMPER_DP,
  30. "name": "binary_sensor_tamper_detect",
  31. "device_class": BinarySensorDeviceClass.TAMPER,
  32. },
  33. ]
  34. )
  35. self.setUpBasicSensor(
  36. BATTERY_DP,
  37. self.entities.get("sensor_battery"),
  38. unit=PERCENTAGE,
  39. device_class=SensorDeviceClass.BATTERY,
  40. )
  41. self.mark_secondary(
  42. ["sensor_battery", "binary_sensor_charging", "binary_sensor_tamper_detect"]
  43. )
  44. def test_supported_features(self):
  45. """Test the supported features of the siren"""
  46. self.assertEqual(
  47. self.subject.supported_features,
  48. SirenEntityFeature.TURN_ON
  49. | SirenEntityFeature.TONES
  50. | SirenEntityFeature.DURATION
  51. | SirenEntityFeature.VOLUME_SET,
  52. )
  53. def test_available_tones(self):
  54. """Test the available tones from the siren"""
  55. self.assertCountEqual(
  56. self.subject.available_tones,
  57. [
  58. "sound",
  59. "light",
  60. "sound+light",
  61. "normal",
  62. ],
  63. )
  64. async def test_set_to_sound(self):
  65. """Test turning on the siren with various parameters"""
  66. async with assert_device_properties_set(
  67. self.subject._device, {TONE_DP: "alarm_sound"}
  68. ):
  69. await self.subject.async_turn_on(tone="sound")
  70. async def test_set_to_light(self):
  71. """Test turning on the siren with various parameters"""
  72. async with assert_device_properties_set(
  73. self.subject._device, {TONE_DP: "alarm_light"}
  74. ):
  75. await self.subject.async_turn_on(tone="light")
  76. async def test_set_to_sound_light(self):
  77. """Test turning on the siren with various parameters"""
  78. async with assert_device_properties_set(
  79. self.subject._device, {TONE_DP: "alarm_sound_light"}
  80. ):
  81. await self.subject.async_turn_on(tone="sound+light")
  82. async def test_set_to_normal(self):
  83. """Test turning on the siren with various parameters"""
  84. async with assert_device_properties_set(
  85. self.subject._device, {TONE_DP: "normal"}
  86. ):
  87. await self.subject.async_turn_on(tone="normal")
  88. async def test_set_volume_low(self):
  89. """Test turning on the siren with various parameters"""
  90. async with assert_device_properties_set(
  91. self.subject._device, {VOLUME_DP: "low"}
  92. ):
  93. await self.subject.async_turn_on(volume=0.3)
  94. async def test_set_volume_mid(self):
  95. """Test turning on the siren with various parameters"""
  96. async with assert_device_properties_set(
  97. self.subject._device, {VOLUME_DP: "middle"}
  98. ):
  99. await self.subject.async_turn_on(volume=0.7)
  100. async def test_set_volume_high(self):
  101. """Test turning on the siren with various parameters"""
  102. async with assert_device_properties_set(
  103. self.subject._device, {VOLUME_DP: "high"}
  104. ):
  105. await self.subject.async_turn_on(volume=1.0)
  106. async def test_set_volume_mute(self):
  107. """Test turning on the siren with various parameters"""
  108. async with assert_device_properties_set(
  109. self.subject._device, {VOLUME_DP: "mute"}
  110. ):
  111. await self.subject.async_turn_on(volume=0.0)
  112. async def test_set_duration(self):
  113. """Test turning on the siren with various parameters"""
  114. async with assert_device_properties_set(self.subject._device, {DURATION_DP: 5}):
  115. await self.subject.async_turn_on(duration=5)
  116. async def test_set_multi(self):
  117. """Test turning on the siren with various parameters"""
  118. async with assert_device_properties_set(
  119. self.subject._device,
  120. {TONE_DP: "alarm_sound", DURATION_DP: 4, VOLUME_DP: "high"},
  121. ):
  122. await self.subject.async_turn_on(tone="sound", duration=4, volume=0.9)
  123. def test_extra_attributes(self):
  124. """Test reading the extra attributes from the siren"""
  125. self.dps[TONE_DP] = "alarm_light"
  126. self.dps[VOLUME_DP] = "middle"
  127. self.dps[DURATION_DP] = 3
  128. self.assertDictEqual(
  129. self.subject.extra_state_attributes,
  130. {
  131. "tone": "light",
  132. "volume_level": 0.67,
  133. "duration": 3,
  134. },
  135. )