test_device_config.py 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. """Test the config parser"""
  2. from custom_components.tuya_local.helpers.device_config import (
  3. available_configs,
  4. TuyaDeviceConfig,
  5. )
  6. from .const import (
  7. DEHUMIDIFIER_PAYLOAD,
  8. EUROM_600_HEATER_PAYLOAD,
  9. FAN_PAYLOAD,
  10. GARDENPAC_HEATPUMP_PAYLOAD,
  11. GECO_HEATER_PAYLOAD,
  12. GPCV_HEATER_PAYLOAD,
  13. GPPH_HEATER_PAYLOAD,
  14. GSH_HEATER_PAYLOAD,
  15. KOGAN_HEATER_PAYLOAD,
  16. KOGAN_SOCKET_PAYLOAD,
  17. KOGAN_SOCKET_PAYLOAD2,
  18. PURLINE_M100_HEATER_PAYLOAD,
  19. )
  20. def test_can_find_config_files():
  21. """Test that the config files can be found by the parser."""
  22. found = False
  23. for cfg in available_configs():
  24. found = True
  25. break
  26. assert found
  27. def test_config_files_parse():
  28. for cfg in available_configs():
  29. parsed = TuyaDeviceConfig(cfg)
  30. assert parsed.name is not None
  31. def test_config_files_have_legacy_link():
  32. """
  33. Initially, we require a link between the new style config, and the old
  34. classes so we can transition over to the new config. When the
  35. transition is complete, we will drop the requirement, as new devices
  36. will only be added as config files.
  37. """
  38. for cfg in available_configs():
  39. parsed = TuyaDeviceConfig(cfg)
  40. assert parsed.primary_entity is not None
  41. assert parsed.primary_entity.legacy_device is not None
  42. for e in parsed.secondary_entities():
  43. assert e.legacy_device is not None
  44. def test_gpph_heater_detection():
  45. """Test that the GPPH heater can be detected from its sample payload."""
  46. parsed = TuyaDeviceConfig("goldair_gpph_heater.yaml")
  47. assert parsed.primary_entity.legacy_device == ".heater.climate.GoldairHeater"
  48. assert parsed.matches(GPPH_HEATER_PAYLOAD)
  49. def test_gpcv_heater_detection():
  50. """Test that the GPCV heater can be detected from its sample payload."""
  51. parsed = TuyaDeviceConfig("goldair_gpcv_heater.yaml")
  52. assert (
  53. parsed.primary_entity.legacy_device == ".gpcv_heater.climate.GoldairGPCVHeater"
  54. )
  55. assert parsed.matches(GPCV_HEATER_PAYLOAD)
  56. def test_eurom_heater_detection():
  57. """Test that the Eurom heater can be detected from its sample payload."""
  58. parsed = TuyaDeviceConfig("eurom_600_heater.yaml")
  59. assert (
  60. parsed.primary_entity.legacy_device
  61. == ".eurom_600_heater.climate.EuromMonSoleil600Heater"
  62. )
  63. assert parsed.matches(EUROM_600_HEATER_PAYLOAD)
  64. def test_geco_heater_detection():
  65. """Test that the GECO heater can be detected from its sample payload."""
  66. parsed = TuyaDeviceConfig("goldair_geco_heater.yaml")
  67. assert (
  68. parsed.primary_entity.legacy_device == ".geco_heater.climate.GoldairGECOHeater"
  69. )
  70. assert parsed.matches(GECO_HEATER_PAYLOAD)
  71. def test_kogan_heater_detection():
  72. """Test that the Kogan heater can be detected from its sample payload."""
  73. parsed = TuyaDeviceConfig("kogan_heater.yaml")
  74. assert parsed.primary_entity.legacy_device == ".kogan_heater.climate.KoganHeater"
  75. assert parsed.matches(KOGAN_HEATER_PAYLOAD)
  76. def test_goldair_dehumidifier_detection():
  77. """Test that the Goldair dehumidifier can be detected from its sample payload."""
  78. parsed = TuyaDeviceConfig("goldair_dehumidifier.yaml")
  79. assert (
  80. parsed.primary_entity.legacy_device
  81. == ".dehumidifier.climate.GoldairDehumidifier"
  82. )
  83. assert parsed.matches(DEHUMIDIFIER_PAYLOAD)
  84. def test_goldair_fan_detection():
  85. """Test that the Goldair fan can be detected from its sample payload."""
  86. parsed = TuyaDeviceConfig("goldair_fan.yaml")
  87. assert parsed.primary_entity.legacy_device == ".fan.climate.GoldairFan"
  88. assert parsed.matches(FAN_PAYLOAD)
  89. def test_kogan_socket_detection():
  90. """Test that the 1st gen Kogan Socket can be detected from its sample payload."""
  91. parsed = TuyaDeviceConfig("kogan_switch.yaml")
  92. assert (
  93. parsed.primary_entity.legacy_device == ".kogan_socket.switch.KoganSocketSwitch"
  94. )
  95. assert parsed.matches(KOGAN_SOCKET_PAYLOAD)
  96. def test_kogan_socket2_detection():
  97. """Test that the 2nd gen Kogan Socket can be detected from its sample payload."""
  98. parsed = TuyaDeviceConfig("kogan_switch2.yaml")
  99. assert (
  100. parsed.primary_entity.legacy_device == ".kogan_socket.switch.KoganSocketSwitch"
  101. )
  102. assert parsed.matches(KOGAN_SOCKET_PAYLOAD2)
  103. def test_gsh_heater_detection():
  104. """Test that the GSH heater can be detected from its sample payload."""
  105. parsed = TuyaDeviceConfig("andersson_gsh_heater.yaml")
  106. assert (
  107. parsed.primary_entity.legacy_device == ".gsh_heater.climate.AnderssonGSHHeater"
  108. )
  109. assert parsed.matches(GSH_HEATER_PAYLOAD)
  110. def test_gardenpac_heatpump_detection():
  111. """Test that the GardenPac heatpump can be detected from its sample payload."""
  112. parsed = TuyaDeviceConfig("gardenpac_heatpump.yaml")
  113. assert (
  114. parsed.primary_entity.legacy_device
  115. == ".gardenpac_heatpump.climate.GardenPACPoolHeatpump"
  116. )
  117. assert parsed.matches(GARDENPAC_HEATPUMP_PAYLOAD)
  118. def test_purline_heater_detection():
  119. """Test that the Purline heater can be detected from its sample payload."""
  120. parsed = TuyaDeviceConfig("purline_m100_heater.yaml")
  121. assert (
  122. parsed.primary_entity.legacy_device
  123. == ".purline_m100_heater.climate.PurlineM100Heater"
  124. )
  125. assert parsed.matches(PURLINE_M100_HEATER_PAYLOAD)