test_orion_outdoor_siren.py 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  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. DEFAULT_TONE = "alarm_sound_light"
  17. class TestOrionSiren(MultiBinarySensorTests, BasicSensorTests, TuyaDeviceTestCase):
  18. __test__ = True
  19. def setUp(self):
  20. self.setUpForConfig("orion_outdoor_siren.yaml", ORION_SIREN_PAYLOAD)
  21. self.subject = self.entities.get("siren")
  22. self.setUpMultiBinarySensors(
  23. [
  24. {
  25. "dps": CHARGING_DP,
  26. "name": "binary_sensor_charging",
  27. "device_class": BinarySensorDeviceClass.BATTERY_CHARGING,
  28. },
  29. {
  30. "dps": TAMPER_DP,
  31. "name": "binary_sensor_tamper_detect",
  32. "device_class": BinarySensorDeviceClass.TAMPER,
  33. },
  34. ]
  35. )
  36. self.setUpBasicSensor(
  37. BATTERY_DP,
  38. self.entities.get("sensor_battery"),
  39. unit=PERCENTAGE,
  40. device_class=SensorDeviceClass.BATTERY,
  41. )
  42. self.mark_secondary(
  43. ["sensor_battery", "binary_sensor_charging", "binary_sensor_tamper_detect"]
  44. )
  45. def test_supported_features(self):
  46. """Test the supported features of the siren"""
  47. self.assertEqual(
  48. self.subject.supported_features,
  49. SirenEntityFeature.TURN_ON
  50. | SirenEntityFeature.TURN_OFF
  51. | SirenEntityFeature.TONES
  52. | SirenEntityFeature.DURATION
  53. | SirenEntityFeature.VOLUME_SET,
  54. )
  55. def test_available_tones(self):
  56. """Test the available tones from the siren"""
  57. self.assertCountEqual(
  58. self.subject.available_tones,
  59. [
  60. "sound",
  61. "light",
  62. "sound+light",
  63. ],
  64. )
  65. async def test_set_to_sound(self):
  66. """Test turning on the siren with various parameters"""
  67. async with assert_device_properties_set(
  68. self.subject._device, {TONE_DP: "alarm_sound"}
  69. ):
  70. await self.subject.async_turn_on(tone="sound")
  71. async def test_set_to_light(self):
  72. """Test turning on the siren with various parameters"""
  73. async with assert_device_properties_set(
  74. self.subject._device, {TONE_DP: "alarm_light"}
  75. ):
  76. await self.subject.async_turn_on(tone="light")
  77. async def test_set_to_sound_light(self):
  78. """Test turning on the siren with various parameters"""
  79. async with assert_device_properties_set(
  80. self.subject._device, {TONE_DP: "alarm_sound_light"}
  81. ):
  82. await self.subject.async_turn_on(tone="sound+light")
  83. async def test_turn_off(self):
  84. """Test turning on the siren with various parameters"""
  85. async with assert_device_properties_set(
  86. self.subject._device, {TONE_DP: "normal"}
  87. ):
  88. await self.subject.async_turn_off()
  89. async def test_turn_on_no_param(self):
  90. """Test turning on the siren with no parameters"""
  91. async with assert_device_properties_set(
  92. self.subject._device,
  93. {TONE_DP: DEFAULT_TONE},
  94. ):
  95. await self.subject.async_turn_on()
  96. async def test_set_volume_low(self):
  97. """Test turning on the siren with various parameters"""
  98. async with assert_device_properties_set(
  99. self.subject._device, {VOLUME_DP: "low", TONE_DP: DEFAULT_TONE}
  100. ):
  101. await self.subject.async_turn_on(volume_level=0.3)
  102. async def test_set_volume_mid(self):
  103. """Test turning on the siren with various parameters"""
  104. async with assert_device_properties_set(
  105. self.subject._device, {VOLUME_DP: "middle", TONE_DP: DEFAULT_TONE}
  106. ):
  107. await self.subject.async_turn_on(volume_level=0.7)
  108. async def test_set_volume_high(self):
  109. """Test turning on the siren with various parameters"""
  110. async with assert_device_properties_set(
  111. self.subject._device, {VOLUME_DP: "high", TONE_DP: DEFAULT_TONE}
  112. ):
  113. await self.subject.async_turn_on(volume_level=1.0)
  114. async def test_set_volume_mute(self):
  115. """Test turning on the siren with various parameters"""
  116. async with assert_device_properties_set(
  117. self.subject._device, {VOLUME_DP: "mute", TONE_DP: DEFAULT_TONE}
  118. ):
  119. await self.subject.async_turn_on(volume_level=0.0)
  120. async def test_set_duration(self):
  121. """Test turning on the siren with various parameters"""
  122. async with assert_device_properties_set(
  123. self.subject._device, {DURATION_DP: 5, TONE_DP: DEFAULT_TONE}
  124. ):
  125. await self.subject.async_turn_on(duration=5)
  126. async def test_set_multi(self):
  127. """Test turning on the siren with various parameters"""
  128. async with assert_device_properties_set(
  129. self.subject._device,
  130. {TONE_DP: "alarm_sound", DURATION_DP: 4, VOLUME_DP: "high"},
  131. ):
  132. await self.subject.async_turn_on(tone="sound", duration=4, volume_level=0.9)
  133. async def test_turn_on_keeps_tone_when_already_on(self):
  134. """Test calling turn_on without a tone parameter when the siren is on"""
  135. self.dps[TONE_DP] = "alarm_light"
  136. async with assert_device_properties_set(
  137. self.subject._device, {VOLUME_DP: "low", TONE_DP: "alarm_light"}
  138. ):
  139. await self.subject.async_turn_on(volume_level=0.5)
  140. def test_is_on(self):
  141. """Test the is_on property"""
  142. self.dps[TONE_DP] = "normal"
  143. self.assertFalse(self.subject.is_on)
  144. self.dps[TONE_DP] = "alarm_light"
  145. self.assertTrue(self.subject.is_on)
  146. self.dps[TONE_DP] = "alarm_sound"
  147. self.assertTrue(self.subject.is_on)
  148. self.dps[TONE_DP] = "alarm_sound_light"
  149. self.assertTrue(self.subject.is_on)
  150. def test_extra_attributes(self):
  151. """Test reading the extra attributes from the siren"""
  152. self.dps[TONE_DP] = "alarm_light"
  153. self.dps[VOLUME_DP] = "middle"
  154. self.dps[DURATION_DP] = 3
  155. self.assertDictEqual(
  156. self.subject.extra_state_attributes,
  157. {
  158. "tone": "light",
  159. "volume_level": 0.67,
  160. "duration": 3,
  161. },
  162. )