test_parkside_plgs2012a1_smart_charger.py 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. """Tests for Parkside PLGS 2012 A1 Smart Charger"""
  2. from homeassistant.components.binary_sensor import BinarySensorDeviceClass
  3. from homeassistant.components.number.const import NumberDeviceClass
  4. from homeassistant.components.sensor import SensorDeviceClass, SensorStateClass
  5. from homeassistant.const import (
  6. PERCENTAGE,
  7. UnitOfElectricCurrent,
  8. UnitOfElectricPotential,
  9. UnitOfTemperature,
  10. UnitOfTime,
  11. )
  12. from ..const import PARKSIDE_PLGS2012A1_PAYLOAD
  13. from ..mixins.binary_sensor import MultiBinarySensorTests
  14. from ..mixins.number import MultiNumberTests
  15. from ..mixins.select import BasicSelectTests
  16. from ..mixins.sensor import MultiSensorTests
  17. from ..mixins.switch import MultiSwitchTests
  18. from .base_device_tests import TuyaDeviceTestCase
  19. SWITCH_DPS = "1"
  20. NAME_DPS = "2"
  21. CURRENT_DPS = "3"
  22. VOLTAGE_DPS = "4"
  23. BATTERY_DPS = "5"
  24. TEMPERATURE_DPS = "6"
  25. MODE_DPS = "7"
  26. STORAGE_DPS = "8"
  27. LIMITER_DPS = "9"
  28. MAXTEMPCOUNT_DPS = "10"
  29. FAULT_DPS = "11"
  30. MAXCURRENT_DPS = "101"
  31. REMAIN_DPS = "102"
  32. ALMOSTCHARGED_DPS = "103"
  33. FULLYCHARGED_DPS = "104"
  34. class TestParksidePLGS2012A1Charger(
  35. MultiBinarySensorTests,
  36. MultiNumberTests,
  37. BasicSelectTests,
  38. MultiSensorTests,
  39. MultiSwitchTests,
  40. TuyaDeviceTestCase,
  41. ):
  42. def setUp(self):
  43. self.setUpForConfig(
  44. "parkside_plgs2012a1_smart_charger.yaml", PARKSIDE_PLGS2012A1_PAYLOAD
  45. )
  46. self.setUpMultiBinarySensors(
  47. [
  48. {
  49. "name": "binary_sensor_almost_charged",
  50. "dps": ALMOSTCHARGED_DPS,
  51. },
  52. {
  53. "name": "binary_sensor_fully_charged",
  54. "dps": FULLYCHARGED_DPS,
  55. },
  56. {
  57. "name": "binary_sensor_problem",
  58. "dps": FAULT_DPS,
  59. "device_class": BinarySensorDeviceClass.PROBLEM,
  60. "testdata": (32, 0),
  61. },
  62. ],
  63. )
  64. self.setUpMultiNumber(
  65. [
  66. {
  67. "name": "number_charge_current",
  68. "dps": CURRENT_DPS,
  69. "device_class": NumberDeviceClass.CURRENT,
  70. "max": 30.000,
  71. "step": 0.1,
  72. "scale": 1000,
  73. "unit": UnitOfElectricCurrent.AMPERE,
  74. },
  75. {
  76. "name": "number_charge_voltage",
  77. "dps": VOLTAGE_DPS,
  78. "device_class": NumberDeviceClass.VOLTAGE,
  79. "max": 25.0,
  80. "scale": 1000,
  81. "step": 0.1,
  82. "unit": UnitOfElectricPotential.VOLT,
  83. },
  84. ],
  85. )
  86. self.setUpBasicSelect(
  87. MODE_DPS,
  88. self.entities.get("select_charge_type"),
  89. {
  90. "ECO": "Eco",
  91. "quick": "Performance",
  92. "standard": "Balanced",
  93. "individual": "Expert",
  94. },
  95. )
  96. self.setUpMultiSensors(
  97. [
  98. {
  99. "name": "sensor_battery",
  100. "dps": BATTERY_DPS,
  101. "unit": PERCENTAGE,
  102. "device_class": SensorDeviceClass.BATTERY,
  103. },
  104. {
  105. "name": "sensor_time_remaining",
  106. "dps": REMAIN_DPS,
  107. "unit": UnitOfTime.MINUTES,
  108. "device_class": SensorDeviceClass.DURATION,
  109. },
  110. {
  111. "name": "sensor_temperature",
  112. "dps": TEMPERATURE_DPS,
  113. "unit": UnitOfTemperature.CELSIUS,
  114. "device_class": SensorDeviceClass.TEMPERATURE,
  115. "state_class": SensorStateClass.MEASUREMENT,
  116. },
  117. {
  118. "name": "sensor_max_current",
  119. "dps": MAXCURRENT_DPS,
  120. "unit": UnitOfElectricCurrent.AMPERE,
  121. "device_class": SensorDeviceClass.CURRENT,
  122. "testdata": (1234, 1.234),
  123. },
  124. {
  125. "name": "sensor_max_temperature_count",
  126. "dps": MAXTEMPCOUNT_DPS,
  127. },
  128. ],
  129. )
  130. self.setUpMultiSwitch(
  131. [
  132. {
  133. "name": "switch",
  134. "dps": SWITCH_DPS,
  135. },
  136. {
  137. "name": "switch_storage",
  138. "dps": STORAGE_DPS,
  139. },
  140. {
  141. "name": "switch_temperature_limiter",
  142. "dps": LIMITER_DPS,
  143. },
  144. ],
  145. )
  146. self.mark_secondary(
  147. [
  148. "number_charge_current",
  149. "number_charge_voltage",
  150. "switch_storage",
  151. "switch_temperature_limiter",
  152. "sensor_temperature",
  153. "sensor_max_temperature_count",
  154. "select_charge_type",
  155. "sensor_max_current",
  156. "binary_sensor_almost_charged",
  157. "binary_sensor_fully_charged",
  158. "binary_sensor_problem",
  159. ]
  160. )
  161. def test_multi_switch_state_attributes(self):
  162. switch = self.multiSwitch.get("switch")
  163. storage = self.multiSwitch.get("switch_storage")
  164. temp = self.multiSwitch.get("switch_temperature_limiter")
  165. self.assertEqual(storage.extra_state_attributes, {})
  166. self.assertEqual(temp.extra_state_attributes, {})
  167. self.dps[NAME_DPS] = "test"
  168. self.assertDictEqual(switch.extra_state_attributes, {"model": "test"})
  169. def test_multi_bsensor_extra_state_attributes(self):
  170. self.dps[FAULT_DPS] = 2
  171. problem = self.multiBSensor.get("binary_sensor_problem")
  172. almost = self.multiBSensor.get("binary_sensor_almost_charged")
  173. fully = self.multiBSensor.get("binary_sensor_fully_charged")
  174. self.assertEqual(almost.extra_state_attributes, {})
  175. self.assertEqual(fully.extra_state_attributes, {})
  176. self.assertCountEqual(problem.extra_state_attributes, {"fault_code": 2})