test_zx_g30_alarm.py 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. """Tests for the ZX G30 Alarm Control Panel."""
  2. from homeassistant.components.alarm_control_panel import (
  3. AlarmControlPanelEntityFeature as Feature,
  4. )
  5. from homeassistant.const import (
  6. STATE_ALARM_ARMED_AWAY,
  7. STATE_ALARM_ARMED_HOME,
  8. STATE_ALARM_DISARMED,
  9. )
  10. from ..const import ZXG30_ALARM_PAYLOAD
  11. from ..helpers import assert_device_properties_set
  12. from .base_device_tests import TuyaDeviceTestCase
  13. ALARMSTATE_DP = "1"
  14. EXITDELAY_DP = "2"
  15. SIRENDURATION_DP = "3"
  16. SIRENTONE_DP = "4"
  17. TAMPER_DP = "9"
  18. VOICE_DP = "10"
  19. POWER_DP = "15"
  20. BATTERY_DP = "16"
  21. LOWBATT_DP = "17"
  22. NOTIFY_DP = "27"
  23. ENTRYDELAY_DP = "28"
  24. TICKDOWN_DP = "29"
  25. class TestZXG30Alarm(TuyaDeviceTestCase):
  26. __test__ = True
  27. def setUp(self):
  28. self.setUpForConfig("zx_g30_alarm.yaml", ZXG30_ALARM_PAYLOAD)
  29. self.subject = self.entities["alarm_control_panel"]
  30. self.mark_secondary(
  31. [
  32. "button_disarm",
  33. "button_away_arm",
  34. "button_home_arm",
  35. "number_exit_delay",
  36. "binary_sensor_tamper",
  37. "switch_voice_prompt",
  38. "binary_sensor_plug",
  39. "binary_sensor_battery",
  40. "switch_alarm_call",
  41. "switch_alarm_sms",
  42. "switch_alarm_notification",
  43. "number_entry_delay",
  44. "switch_tick_down",
  45. "button_factory_reset",
  46. ]
  47. )
  48. def test_supported_features(self):
  49. self.assertEqual(
  50. self.subject.supported_features,
  51. Feature.ARM_AWAY | Feature.ARM_HOME,
  52. )
  53. def test_state(self):
  54. self.dps[ALARMSTATE_DP] = "disarmed"
  55. self.assertEqual(self.subject.state, STATE_ALARM_DISARMED)
  56. async def test_arm_home(self):
  57. async with assert_device_properties_set(
  58. self.subject._device,
  59. {ALARMSTATE_DP: "home"},
  60. ):
  61. await self.subject.async_alarm_arm_home()
  62. async def test_arm_away(self):
  63. async with assert_device_properties_set(
  64. self.subject._device,
  65. {ALARMSTATE_DP: "arm"},
  66. ):
  67. await self.subject.async_alarm_arm_away()
  68. async def test_disarm(self):
  69. async with assert_device_properties_set(
  70. self.subject._device,
  71. {ALARMSTATE_DP: "disarmed"},
  72. ):
  73. await self.subject.async_alarm_disarm()
  74. async def test_arm_vacation_fails_when_not_supported(self):
  75. with self.assertRaises(NotImplementedError):
  76. await self.subject.async_alarm_arm_vacation()
  77. async def test_trigger_fails_when_not_supported(self):
  78. with self.assertRaises(NotImplementedError):
  79. await self.subject.async_alarm_trigger()