Skip to content

Commit

Permalink
Merge pull request #66 from Patrick762/ac180-ac180p
Browse files Browse the repository at this point in the history
AC180 AC180P
  • Loading branch information
Patrick762 authored Feb 25, 2024
2 parents 85e5049 + df83750 commit ec657ad
Show file tree
Hide file tree
Showing 7 changed files with 156 additions and 3 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ After the installation, you can use this button to install the integration:
### Supported devices:

- AC60
- AC180 (basic data)
- AC180P (basic data)
- AC200M
- AC300 (tested)
- AC500
Expand Down
8 changes: 8 additions & 0 deletions custom_components/bluetti_bt/bluetti_bt_lib/devices/ac180.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
"""AC180 fields."""

from ..base_devices.ProtocolV2Device import ProtocolV2Device


class AC180(ProtocolV2Device):
def __init__(self, address: str, sn: str):
super().__init__(address, "AC180", sn)
8 changes: 8 additions & 0 deletions custom_components/bluetti_bt/bluetti_bt_lib/devices/ac180p.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
"""AC180P fields."""

from ..base_devices.ProtocolV2Device import ProtocolV2Device


class AC180P(ProtocolV2Device):
def __init__(self, address: str, sn: str):
super().__init__(address, "AC180P", sn)
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import re

from ..devices.ac60 import AC60
from ..devices.ac180 import AC180
from ..devices.ac180p import AC180P
from ..devices.ac200m import AC200M
from ..devices.ac300 import AC300
from ..devices.ac500 import AC500
Expand All @@ -14,14 +16,18 @@
from ..devices.ep800 import EP800

DEVICE_NAME_RE = re.compile(
r"^(AC60|AC200M|AC300|AC500|EB3A|EP500|EP500P|EP600|EP760|EP800)(\d+)$"
r"^(AC60|AC180|AC180P|AC200M|AC300|AC500|EB3A|EP500|EP500P|EP600|EP760|EP800)(\d+)$"
)


def build_device(address: str, name: str):
match = DEVICE_NAME_RE.match(name)
if match[1] == "AC60":
return AC60(address, match[2])
if match[1] == "AC180":
return AC180(address, match[2])
if match[1] == "AC180P":
return AC180P(address, match[2])
if match[1] == "AC200M":
return AC200M(address, match[2])
if match[1] == "AC300":
Expand Down
5 changes: 3 additions & 2 deletions custom_components/bluetti_bt/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
"domain": "bluetti_bt",
"name": "Bluetti BT",
"bluetooth": [
{ "local_name": "AC60*" },
{ "local_name": "AC180*" },
{ "local_name": "AC200M*" },
{ "local_name": "AC300*" },
{ "local_name": "AC500*" },
{ "local_name": "AC60*" },
{ "local_name": "EB3A*" },
{ "local_name": "EP500*" },
{ "local_name": "EP600*" },
Expand All @@ -21,5 +22,5 @@
"iot_class": "local_polling",
"issue_tracker": "https://github.com/Patrick762/hassio-bluetti-bt/issues",
"requirements": [],
"version": "0.0.18"
"version": "0.0.19"
}
4 changes: 4 additions & 0 deletions test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh

# Execute unittests of python library
python3 -m unittest discover -s tests -p "*_test.py"
124 changes: 124 additions & 0 deletions tests/device_builder_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
"""Unittest for device builder."""

import unittest

from custom_components.bluetti_bt.bluetti_bt_lib.utils.device_builder import build_device
from custom_components.bluetti_bt.bluetti_bt_lib.devices.ac60 import AC60
from custom_components.bluetti_bt.bluetti_bt_lib.devices.ac180 import AC180
from custom_components.bluetti_bt.bluetti_bt_lib.devices.ac180p import AC180P
from custom_components.bluetti_bt.bluetti_bt_lib.devices.ac200m import AC200M
from custom_components.bluetti_bt.bluetti_bt_lib.devices.ac300 import AC300
from custom_components.bluetti_bt.bluetti_bt_lib.devices.ac500 import AC500
from custom_components.bluetti_bt.bluetti_bt_lib.devices.eb3a import EB3A
from custom_components.bluetti_bt.bluetti_bt_lib.devices.ep500 import EP500
from custom_components.bluetti_bt.bluetti_bt_lib.devices.ep500p import EP500P
from custom_components.bluetti_bt.bluetti_bt_lib.devices.ep600 import EP600
from custom_components.bluetti_bt.bluetti_bt_lib.devices.ep760 import EP760
from custom_components.bluetti_bt.bluetti_bt_lib.devices.ep800 import EP800


class TestDeviceBuilder(unittest.TestCase):
def test_build_Unknow(self):
bt_addr = "aa:bb:cc:dd:ee:ff"
bt_name = "PBOX56786746478"
with self.assertRaises(TypeError):
build_device(bt_addr, bt_name)

def test_build_ac60(self):
bt_addr = "aa:bb:cc:dd:ee:ff"
bt_name = "AC6056786746478"
built = build_device(bt_addr, bt_name)

self.assertIsInstance(built, AC60)
self.assertEqual(built.address, bt_addr)

def test_build_ac180(self):
bt_addr = "aa:bb:cc:dd:ee:ff"
bt_name = "AC18056786746478"
built = build_device(bt_addr, bt_name)

self.assertIsInstance(built, AC180)
self.assertEqual(built.address, bt_addr)

def test_build_ac180p(self):
bt_addr = "aa:bb:cc:dd:ee:ff"
bt_name = "AC180P56786746478"
built = build_device(bt_addr, bt_name)

self.assertIsInstance(built, AC180P)
self.assertEqual(built.address, bt_addr)

def test_build_ac200m(self):
bt_addr = "aa:bb:cc:dd:ee:ff"
bt_name = "AC200M56786746478"
built = build_device(bt_addr, bt_name)

self.assertIsInstance(built, AC200M)
self.assertEqual(built.address, bt_addr)

def test_build_ac300(self):
bt_addr = "aa:bb:cc:dd:ee:ff"
bt_name = "AC30056786746478"
built = build_device(bt_addr, bt_name)

self.assertIsInstance(built, AC300)
self.assertEqual(built.address, bt_addr)

def test_build_ac500(self):
bt_addr = "aa:bb:cc:dd:ee:ff"
bt_name = "AC50056786746478"
built = build_device(bt_addr, bt_name)

self.assertIsInstance(built, AC500)
self.assertEqual(built.address, bt_addr)

def test_build_eb3a(self):
bt_addr = "aa:bb:cc:dd:ee:ff"
bt_name = "EB3A56786746478"
built = build_device(bt_addr, bt_name)

self.assertIsInstance(built, EB3A)
self.assertEqual(built.address, bt_addr)

def test_build_ep500(self):
bt_addr = "aa:bb:cc:dd:ee:ff"
bt_name = "EP50056786746478"
built = build_device(bt_addr, bt_name)

self.assertIsInstance(built, EP500)
self.assertEqual(built.address, bt_addr)

def test_build_ep500p(self):
bt_addr = "aa:bb:cc:dd:ee:ff"
bt_name = "EP500P56786746478"
built = build_device(bt_addr, bt_name)

self.assertIsInstance(built, EP500P)
self.assertEqual(built.address, bt_addr)

def test_build_EP600(self):
bt_addr = "aa:bb:cc:dd:ee:ff"
bt_name = "EP60056786746478"
built = build_device(bt_addr, bt_name)

self.assertIsInstance(built, EP600)
self.assertEqual(built.address, bt_addr)

def test_build_EP760(self):
bt_addr = "aa:bb:cc:dd:ee:ff"
bt_name = "EP76056786746478"
built = build_device(bt_addr, bt_name)

self.assertIsInstance(built, EP760)
self.assertEqual(built.address, bt_addr)

def test_build_EP800(self):
bt_addr = "aa:bb:cc:dd:ee:ff"
bt_name = "EP80056786746478"
built = build_device(bt_addr, bt_name)

self.assertIsInstance(built, EP800)
self.assertEqual(built.address, bt_addr)

if __name__ == '__main__':
unittest.main()

0 comments on commit ec657ad

Please sign in to comment.