test_smartplug_encoded.py 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. """Tests for the switch entity."""
  2. from homeassistant.components.number import NumberDeviceClass
  3. from homeassistant.components.switch import SwitchDeviceClass
  4. from homeassistant.const import UnitOfTime
  5. from ..const import SMARTPLUG_ENCODED_PAYLOAD
  6. from ..mixins.number import BasicNumberTests
  7. from ..mixins.switch import SwitchableTests
  8. from .base_device_tests import TuyaDeviceTestCase
  9. SWITCH_DPS = "1"
  10. TIMER_DPS = "11"
  11. RANDOM_DPS = "101"
  12. CIRCULATE_DPS = "102"
  13. SCHEDULE_DPS = "103"
  14. class TestSwitchEncoded(BasicNumberTests, SwitchableTests, TuyaDeviceTestCase):
  15. __test__ = True
  16. def setUp(self):
  17. self.setUpForConfig("smartplug_encoded.yaml", SMARTPLUG_ENCODED_PAYLOAD)
  18. self.subject = self.entities.get("switch_outlet")
  19. self.setUpSwitchable(SWITCH_DPS, self.subject)
  20. self.setUpBasicNumber(
  21. TIMER_DPS,
  22. self.entities.get("number_timer"),
  23. max=1440.0,
  24. unit=UnitOfTime.MINUTES,
  25. device_class=NumberDeviceClass.DURATION,
  26. scale=60,
  27. )
  28. self.mark_secondary(["number_timer"])
  29. def test_device_class_is_outlet(self):
  30. self.assertEqual(self.subject.device_class, SwitchDeviceClass.OUTLET)
  31. def test_extra_state_attributes_set(self):
  32. self.dps[RANDOM_DPS] = "101"
  33. self.dps[CIRCULATE_DPS] = "102"
  34. self.dps[SCHEDULE_DPS] = "103"
  35. self.assertDictEqual(
  36. self.subject.extra_state_attributes,
  37. {
  38. "random": "101",
  39. "circulate": "102",
  40. "schedule": "103",
  41. },
  42. )