test_smartplugv2.py 2.8 KB

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