test_parkside_plgs2012a1_smart_charger.py 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  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. __test__ = True
  43. def setUp(self):
  44. self.setUpForConfig(
  45. "parkside_plgs2012a1_smart_charger.yaml", PARKSIDE_PLGS2012A1_PAYLOAD
  46. )
  47. self.setUpMultiBinarySensors(
  48. [
  49. {
  50. "name": "binary_sensor_almost_charged",
  51. "dps": ALMOSTCHARGED_DPS,
  52. },
  53. {
  54. "name": "binary_sensor_fully_charged",
  55. "dps": FULLYCHARGED_DPS,
  56. },
  57. {
  58. "name": "binary_sensor_problem",
  59. "dps": FAULT_DPS,
  60. "device_class": BinarySensorDeviceClass.PROBLEM,
  61. "testdata": (32, 0),
  62. },
  63. ],
  64. )
  65. self.setUpMultiNumber(
  66. [
  67. {
  68. "name": "number_charge_current",
  69. "dps": CURRENT_DPS,
  70. "device_class": NumberDeviceClass.CURRENT,
  71. "max": 30.000,
  72. "step": 0.1,
  73. "scale": 1000,
  74. "unit": UnitOfElectricCurrent.AMPERE,
  75. },
  76. {
  77. "name": "number_charge_voltage",
  78. "dps": VOLTAGE_DPS,
  79. "device_class": NumberDeviceClass.VOLTAGE,
  80. "max": 25.0,
  81. "scale": 1000,
  82. "step": 0.1,
  83. "unit": UnitOfElectricPotential.VOLT,
  84. },
  85. ],
  86. )
  87. self.setUpBasicSelect(
  88. MODE_DPS,
  89. self.entities.get("select_charge_type"),
  90. {
  91. "ECO": "Eco",
  92. "quick": "Performance",
  93. "standard": "Balanced",
  94. "individual": "Expert",
  95. },
  96. )
  97. self.setUpMultiSensors(
  98. [
  99. {
  100. "name": "sensor_battery",
  101. "dps": BATTERY_DPS,
  102. "unit": PERCENTAGE,
  103. "device_class": SensorDeviceClass.BATTERY,
  104. },
  105. {
  106. "name": "sensor_time_remaining",
  107. "dps": REMAIN_DPS,
  108. "unit": UnitOfTime.MINUTES,
  109. "device_class": SensorDeviceClass.DURATION,
  110. },
  111. {
  112. "name": "sensor_temperature",
  113. "dps": TEMPERATURE_DPS,
  114. "unit": UnitOfTemperature.CELSIUS,
  115. "device_class": SensorDeviceClass.TEMPERATURE,
  116. "state_class": SensorStateClass.MEASUREMENT,
  117. },
  118. {
  119. "name": "sensor_max_current",
  120. "dps": MAXCURRENT_DPS,
  121. "unit": UnitOfElectricCurrent.AMPERE,
  122. "device_class": SensorDeviceClass.CURRENT,
  123. "testdata": (1234, 1.234),
  124. },
  125. {
  126. "name": "sensor_max_temperature_count",
  127. "dps": MAXTEMPCOUNT_DPS,
  128. },
  129. ],
  130. )
  131. self.setUpMultiSwitch(
  132. [
  133. {
  134. "name": "switch",
  135. "dps": SWITCH_DPS,
  136. },
  137. {
  138. "name": "switch_storage",
  139. "dps": STORAGE_DPS,
  140. },
  141. {
  142. "name": "switch_temperature_limiter",
  143. "dps": LIMITER_DPS,
  144. },
  145. ],
  146. )
  147. self.mark_secondary(
  148. [
  149. "number_charge_current",
  150. "number_charge_voltage",
  151. "switch_storage",
  152. "switch_temperature_limiter",
  153. "sensor_temperature",
  154. "sensor_max_temperature_count",
  155. "select_charge_type",
  156. "sensor_max_current",
  157. "binary_sensor_almost_charged",
  158. "binary_sensor_fully_charged",
  159. "binary_sensor_problem",
  160. ]
  161. )
  162. def test_multi_switch_state_attributes(self):
  163. switch = self.multiSwitch.get("switch")
  164. storage = self.multiSwitch.get("switch_storage")
  165. temp = self.multiSwitch.get("switch_temperature_limiter")
  166. self.assertEqual(storage.extra_state_attributes, {})
  167. self.assertEqual(temp.extra_state_attributes, {})
  168. self.dps[NAME_DPS] = "test"
  169. self.assertDictEqual(switch.extra_state_attributes, {"model": "test"})
  170. def test_multi_bsensor_extra_state_attributes(self):
  171. self.dps[FAULT_DPS] = 2
  172. problem = self.multiBSensor.get("binary_sensor_problem")
  173. almost = self.multiBSensor.get("binary_sensor_almost_charged")
  174. fully = self.multiBSensor.get("binary_sensor_fully_charged")
  175. self.assertEqual(almost.extra_state_attributes, {})
  176. self.assertEqual(fully.extra_state_attributes, {})
  177. self.assertCountEqual(problem.extra_state_attributes, {"fault_code": 2})