4
0

test_smartplugv2.py 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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=1440.0,
  33. unit=UnitOfTime.MINUTES,
  34. device_class=NumberDeviceClass.DURATION,
  35. scale=60,
  36. )
  37. self.setUpMultiSensors(
  38. [
  39. {
  40. "name": "sensor_voltage",
  41. "dps": VOLTAGE_DPS,
  42. "unit": UnitOfElectricPotential.VOLT,
  43. "device_class": SensorDeviceClass.VOLTAGE,
  44. "state_class": "measurement",
  45. "testdata": (2300, 230.0),
  46. },
  47. {
  48. "name": "sensor_current",
  49. "dps": CURRENT_DPS,
  50. "unit": UnitOfElectricCurrent.MILLIAMPERE,
  51. "device_class": SensorDeviceClass.CURRENT,
  52. "state_class": "measurement",
  53. },
  54. {
  55. "name": "sensor_power",
  56. "dps": POWER_DPS,
  57. "unit": UnitOfPower.WATT,
  58. "device_class": SensorDeviceClass.POWER,
  59. "state_class": "measurement",
  60. "testdata": (1234, 123.4),
  61. },
  62. ]
  63. )
  64. self.mark_secondary(
  65. [
  66. "binary_sensor_problem",
  67. "number_timer",
  68. "sensor_current",
  69. "sensor_power",
  70. "sensor_voltage",
  71. "time_timer",
  72. ]
  73. )
  74. def test_device_class_is_outlet(self):
  75. self.assertEqual(self.subject.device_class, SwitchDeviceClass.OUTLET)
  76. def test_sensor_precision(self):
  77. self.assertEqual(self.multiSensor["sensor_current"].native_precision, 0)
  78. self.assertEqual(self.multiSensor["sensor_power"].native_precision, 1)
  79. self.assertEqual(self.multiSensor["sensor_voltage"].native_precision, 1)