test_smartplugv2.py 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. """Tests for the switch entity."""
  2. from homeassistant.components.number import NumberDeviceClass
  3. from homeassistant.components.sensor import SensorDeviceClass
  4. from homeassistant.components.switch import SwitchDeviceClass
  5. from homeassistant.const import (
  6. UnitOfElectricCurrent,
  7. UnitOfElectricPotential,
  8. UnitOfPower,
  9. UnitOfTime,
  10. )
  11. from ..const import KOGAN_SOCKET_PAYLOAD2
  12. from ..mixins.number import BasicNumberTests
  13. from ..mixins.sensor import MultiSensorTests
  14. from ..mixins.switch import SwitchableTests
  15. from .base_device_tests import TuyaDeviceTestCase
  16. SWITCH_DPS = "1"
  17. TIMER_DPS = "9"
  18. CURRENT_DPS = "18"
  19. POWER_DPS = "19"
  20. VOLTAGE_DPS = "20"
  21. class TestSwitchV2(
  22. BasicNumberTests, MultiSensorTests, SwitchableTests, TuyaDeviceTestCase
  23. ):
  24. __test__ = True
  25. def setUp(self):
  26. self.setUpForConfig("smartplugv2.yaml", KOGAN_SOCKET_PAYLOAD2)
  27. self.subject = self.entities.get("switch_outlet")
  28. self.setUpSwitchable(SWITCH_DPS, self.subject)
  29. self.setUpBasicNumber(
  30. TIMER_DPS,
  31. self.entities.get("number_timer"),
  32. max=86400,
  33. unit=UnitOfTime.SECONDS,
  34. device_class=NumberDeviceClass.DURATION,
  35. )
  36. self.setUpMultiSensors(
  37. [
  38. {
  39. "name": "sensor_voltage",
  40. "dps": VOLTAGE_DPS,
  41. "unit": UnitOfElectricPotential.VOLT,
  42. "device_class": SensorDeviceClass.VOLTAGE,
  43. "state_class": "measurement",
  44. "testdata": (2300, 230.0),
  45. },
  46. {
  47. "name": "sensor_current",
  48. "dps": CURRENT_DPS,
  49. "unit": UnitOfElectricCurrent.MILLIAMPERE,
  50. "device_class": SensorDeviceClass.CURRENT,
  51. "state_class": "measurement",
  52. },
  53. {
  54. "name": "sensor_power",
  55. "dps": POWER_DPS,
  56. "unit": UnitOfPower.WATT,
  57. "device_class": SensorDeviceClass.POWER,
  58. "state_class": "measurement",
  59. "testdata": (1234, 123.4),
  60. },
  61. ]
  62. )
  63. self.mark_secondary(
  64. [
  65. "binary_sensor_problem",
  66. "number_timer",
  67. "sensor_current",
  68. "sensor_power",
  69. "sensor_voltage",
  70. ]
  71. )
  72. def test_device_class_is_outlet(self):
  73. self.assertEqual(self.subject.device_class, SwitchDeviceClass.OUTLET)
  74. def test_sensor_precision(self):
  75. self.assertEqual(self.multiSensor["sensor_current"].native_precision, 0)
  76. self.assertEqual(self.multiSensor["sensor_power"].native_precision, 1)
  77. self.assertEqual(self.multiSensor["sensor_voltage"].native_precision, 1)