Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: add AC2A support #125

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions bluetti_mqtt/bluetooth/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
from typing import Set
from bleak import BleakScanner
from bleak.backends.device import BLEDevice
from bluetti_mqtt.core import BluettiDevice, AC200M, AC300, AC500, AC60, EP500, EP500P, EP600, EB3A
from bluetti_mqtt.core import BluettiDevice, AC200M, AC300, AC500, AC60, EP500, EP500P, EP600, EB3A, AC2A
from .client import BluetoothClient
from .exc import BadConnectionError, ModbusError, ParseError
from .manager import MultiDeviceManager


DEVICE_NAME_RE = re.compile(r'^(AC200M|AC300|AC500|AC60|EP500P|EP500|EP600|EB3A)(\d+)$')
DEVICE_NAME_RE = re.compile(r'^(AC200M|AC300|AC500|AC60|AC2A|EP500P|EP500|EP600|EB3A)(\d+)$')


async def scan_devices():
Expand Down Expand Up @@ -41,6 +41,8 @@ def build_device(address: str, name: str):
return EP600(address, match[2])
if match[1] == 'EB3A':
return EB3A(address, match[2])
if match[1] == 'AC2A':
return AC2A(address, match[2])


async def check_addresses(addresses: Set[str]):
Expand Down
1 change: 1 addition & 0 deletions bluetti_mqtt/core/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from .devices.ep500p import EP500P
from .devices.ep600 import EP600
from .devices.eb3a import EB3A
from .devices.ac2a import AC2A
from .commands import (
DeviceCommand,
ReadHoldingRegisters,
Expand Down
57 changes: 57 additions & 0 deletions bluetti_mqtt/core/devices/ac2a.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
from typing import List
from ..commands import ReadHoldingRegisters
from .bluetti_device import BluettiDevice
from .struct import DeviceStruct


class AC2A(BluettiDevice):
def __init__(self, address: str, sn: str):
self.struct = DeviceStruct()

# Core device properties
self.struct.add_uint_field('total_battery_percent', 102)
self.struct.add_swap_string_field('device_type', 110, 6)
self.struct.add_sn_field('serial_number', 116)
self.struct.add_decimal_field('power_generation', 154, 1)

# AC/DC output on/off states found in bit 3/4
# self.struct.add_uint_field('ac_output_on', 1131) # bit 3
# self.struct.add_uint_field('dc_output_on', 1131) # bit 4

# Input power
self.struct.add_uint_field('dc_input_power', 1200)
self.struct.add_uint_field('ac_input_power', 1313)

# Output power
self.struct.add_uint_field('dc_output_power', 1400)
self.struct.add_uint_field('ac_output_power', 1420)

# ac_output_power_on is the electrical relay (delay of ~1s to ac_output_on)
# self.struct.add_bool_field('ac_output_power_on', 1509)
# self.struct.add_uint_field('ac_output_power', 1510)

# Output buttons
self.struct.add_bool_field('dc_output_on', 2012)
self.struct.add_bool_field('ac_output_on', 2011)

super().__init__(address, "AC2A", sn)

@property
def logging_commands(self) -> List[ReadHoldingRegisters]:
return [
ReadHoldingRegisters(100, 62), # Device info
# ReadHoldingRegisters(1100, 51), # AC/DC output on/off
ReadHoldingRegisters(1200, 90), # DC input power
ReadHoldingRegisters(1300, 31), # AC input power

ReadHoldingRegisters(1400, 48), # AC/DC output power

# ReadHoldingRegisters(1500, 30), # AC output power and on/of

ReadHoldingRegisters(2000, 67), # DC output on/off

# ReadHoldingRegisters(2200, 29),
# ReadHoldingRegisters(6000, 31),
# ReadHoldingRegisters(6100, 100),
# ReadHoldingRegisters(6300, 52),
]