test_orion_outdoor_siren.py 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  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. 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.TURN_OFF
  50. | SirenEntityFeature.TONES
  51. | SirenEntityFeature.DURATION
  52. | SirenEntityFeature.VOLUME_SET,
  53. )
  54. def test_available_tones(self):
  55. """Test the available tones from the siren"""
  56. self.assertCountEqual(
  57. self.subject.available_tones,
  58. [
  59. "sound",
  60. "light",
  61. "sound+light",
  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_turn_off(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_off()
  88. async def test_turn_on_no_param(self):
  89. """Test turning on the siren with no parameters"""
  90. async with assert_device_properties_set(
  91. self.subject._device,
  92. {TONE_DP: DEFAULT_TONE},
  93. ):
  94. await self.subject.async_turn_on()
  95. async def test_set_volume_low(self):
  96. """Test turning on the siren with various parameters"""
  97. async with assert_device_properties_set(
  98. self.subject._device, {VOLUME_DP: "low", TONE_DP: DEFAULT_TONE}
  99. ):
  100. await self.subject.async_turn_on(volume_level=0.3)
  101. async def test_set_volume_mid(self):
  102. """Test turning on the siren with various parameters"""
  103. async with assert_device_properties_set(
  104. self.subject._device, {VOLUME_DP: "middle", TONE_DP: DEFAULT_TONE}
  105. ):
  106. await self.subject.async_turn_on(volume_level=0.7)
  107. async def test_set_volume_high(self):
  108. """Test turning on the siren with various parameters"""
  109. async with assert_device_properties_set(
  110. self.subject._device, {VOLUME_DP: "high", TONE_DP: DEFAULT_TONE}
  111. ):
  112. await self.subject.async_turn_on(volume_level=1.0)
  113. async def test_set_volume_mute(self):
  114. """Test turning on the siren with various parameters"""
  115. async with assert_device_properties_set(
  116. self.subject._device, {VOLUME_DP: "mute", TONE_DP: DEFAULT_TONE}
  117. ):
  118. await self.subject.async_turn_on(volume_level=0.0)
  119. async def test_set_duration(self):
  120. """Test turning on the siren with various parameters"""
  121. async with assert_device_properties_set(
  122. self.subject._device, {DURATION_DP: 5, TONE_DP: DEFAULT_TONE}
  123. ):
  124. await self.subject.async_turn_on(duration=5)
  125. async def test_set_multi(self):
  126. """Test turning on the siren with various parameters"""
  127. async with assert_device_properties_set(
  128. self.subject._device,
  129. {TONE_DP: "alarm_sound", DURATION_DP: 4, VOLUME_DP: "high"},
  130. ):
  131. await self.subject.async_turn_on(tone="sound", duration=4, volume_level=0.9)
  132. async def test_turn_on_keeps_tone_when_already_on(self):
  133. """Test calling turn_on without a tone parameter when the siren is on"""
  134. self.dps[TONE_DP] = "alarm_light"
  135. async with assert_device_properties_set(
  136. self.subject._device, {VOLUME_DP: "low", TONE_DP: "alarm_light"}
  137. ):
  138. await self.subject.async_turn_on(volume_level=0.5)
  139. def test_is_on(self):
  140. """Test the is_on property"""
  141. self.dps[TONE_DP] = "normal"
  142. self.assertFalse(self.subject.is_on)
  143. self.dps[TONE_DP] = "alarm_light"
  144. self.assertTrue(self.subject.is_on)
  145. self.dps[TONE_DP] = "alarm_sound"
  146. self.assertTrue(self.subject.is_on)
  147. self.dps[TONE_DP] = "alarm_sound_light"
  148. self.assertTrue(self.subject.is_on)
  149. def test_extra_attributes(self):
  150. """Test reading the extra attributes from the siren"""
  151. self.dps[TONE_DP] = "alarm_light"
  152. self.dps[VOLUME_DP] = "middle"
  153. self.dps[DURATION_DP] = 3
  154. self.assertDictEqual(
  155. self.subject.extra_state_attributes,
  156. {
  157. "tone": "light",
  158. "volume_level": 0.67,
  159. "duration": 3,
  160. },
  161. )