Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ba6611b084 | ||
|
|
3e4b8601e8 | ||
|
|
ebbcea3c4c |
No files matched your search
@@ -12,8 +12,6 @@ from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.entity import DeviceInfo
|
||||
from homeassistant.exceptions import ConfigEntryNotReady
|
||||
|
||||
from bluetti_mqtt.bluetooth import build_device as orig_build_device
|
||||
|
||||
from .const import (
|
||||
CONF_MAX_RETRIES,
|
||||
CONF_PERSISTENT_CONN,
|
||||
@@ -22,13 +20,10 @@ from .const import (
|
||||
CONF_USE_CONTROLS,
|
||||
DATA_COORDINATOR,
|
||||
DATA_POLLING_RUNNING,
|
||||
DEVICE_NAME_RE,
|
||||
DOMAIN,
|
||||
MANUFACTURER,
|
||||
)
|
||||
from .coordinator import PollingCoordinator
|
||||
from .devices.ep600 import EP600
|
||||
from .devices.ep760 import EP760
|
||||
|
||||
PLATFORMS: [Platform] = [Platform.BINARY_SENSOR, Platform.SENSOR]
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
@@ -110,12 +105,3 @@ def get_type_by_bt_name(bt_name: str):
|
||||
elif bt_name.startswith("EP760"):
|
||||
dev_type = "EP760"
|
||||
return dev_type
|
||||
|
||||
def build_device(address: str, name: str):
|
||||
match = DEVICE_NAME_RE.match(name)
|
||||
if match[1] == 'EP760':
|
||||
return EP760(address, match[2])
|
||||
elif match[1] == 'EP600':
|
||||
return EP600(address, match[2])
|
||||
else:
|
||||
return orig_build_device(address, name)
|
||||
@@ -24,10 +24,10 @@ from bluetti_mqtt.mqtt_client import (
|
||||
MqttFieldType,
|
||||
)
|
||||
|
||||
from . import device_info as dev_info, get_unique_id, build_device
|
||||
from . import device_info as dev_info, get_unique_id
|
||||
from .const import DATA_COORDINATOR, DOMAIN, ADDITIONAL_DEVICE_FIELDS
|
||||
from .coordinator import PollingCoordinator
|
||||
from .utils import unique_id_loggable
|
||||
from .utils import unique_id_loggable, build_device
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@@ -24,6 +24,7 @@ from .const import (
|
||||
CONF_POLLING_TIMEOUT,
|
||||
CONF_USE_CONTROLS,
|
||||
DOMAIN,
|
||||
SUPPORTED_MODELS,
|
||||
)
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
@@ -58,12 +59,18 @@ class BluettiConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
||||
await self.async_set_unique_id(address, raise_on_progress=False)
|
||||
self._abort_if_unique_id_configured()
|
||||
dev_type = get_type_by_bt_name(discovery_info.name)
|
||||
name = re.sub("[^A-Z0-9]+", "", discovery_info.name)
|
||||
|
||||
if dev_type == "Unknown":
|
||||
dev_type = user_input[CONF_TYPE]
|
||||
name = name.replace("PBOX", dev_type)
|
||||
|
||||
return self.async_create_entry(
|
||||
title=discovery_info.name,
|
||||
title=name,
|
||||
data={
|
||||
CONF_ADDRESS: discovery_info.address,
|
||||
CONF_TYPE: dev_type,
|
||||
CONF_NAME: re.sub("[^A-Z0-9]+", "", discovery_info.name),
|
||||
CONF_NAME: name,
|
||||
},
|
||||
)
|
||||
|
||||
@@ -88,6 +95,12 @@ class BluettiConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
||||
for service_info in self._discovered_devices.values()
|
||||
}
|
||||
),
|
||||
vol.Optional(CONF_TYPE): vol.In(
|
||||
{
|
||||
model: model
|
||||
for model in SUPPORTED_MODELS
|
||||
}
|
||||
),
|
||||
}
|
||||
)
|
||||
return self.async_show_form(
|
||||
|
||||
@@ -17,6 +17,17 @@ CONF_MAX_RETRIES = "max_retries"
|
||||
DATA_COORDINATOR = "coordinator"
|
||||
DATA_POLLING_RUNNING = "polling_running"
|
||||
|
||||
SUPPORTED_MODELS = [
|
||||
"AC60",
|
||||
"AC200M",
|
||||
"AC300",
|
||||
"AC500",
|
||||
"EB3A",
|
||||
"EP500",
|
||||
"EP500P",
|
||||
"EP600",
|
||||
"EP760",
|
||||
]
|
||||
DEVICE_NAME_RE = re.compile(r'^(AC200M|AC300|AC500|AC60|EP500P|EP500|EP600|EP760|EB3A)(\d+)$')
|
||||
|
||||
CONTROL_FIELDS = [
|
||||
|
||||
@@ -25,9 +25,8 @@ from bluetti_mqtt.bluetooth import (
|
||||
from bluetti_mqtt.core.devices.bluetti_device import BluettiDevice
|
||||
from bluetti_mqtt.core.commands import ReadHoldingRegisters
|
||||
|
||||
from . import build_device
|
||||
from .const import DATA_POLLING_RUNNING, DOMAIN
|
||||
from .utils import mac_loggable
|
||||
from .utils import mac_loggable, build_device
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@@ -9,7 +9,8 @@
|
||||
{ "local_name": "EB3A*" },
|
||||
{ "local_name": "EP500*" },
|
||||
{ "local_name": "EP600*" },
|
||||
{ "local_name": "EP760*" }
|
||||
{ "local_name": "EP760*" },
|
||||
{ "local_name": "PBOX*" }
|
||||
],
|
||||
"codeowners": ["@Patrick762"],
|
||||
"config_flow": true,
|
||||
@@ -19,5 +20,5 @@
|
||||
"iot_class": "local_polling",
|
||||
"issue_tracker": "https://github.com/Patrick762/hassio-bluetti-bt/issues",
|
||||
"requirements": ["bluetti_mqtt==0.15.0"],
|
||||
"version": "0.0.13"
|
||||
"version": "0.0.15"
|
||||
}
|
||||
@@ -29,10 +29,10 @@ from bluetti_mqtt.mqtt_client import (
|
||||
battery_pack_fields,
|
||||
)
|
||||
|
||||
from . import device_info as dev_info, get_unique_id, build_device
|
||||
from . import device_info as dev_info, get_unique_id
|
||||
from .const import DATA_COORDINATOR, DOMAIN, CONF_OPTIONS, DIAGNOSTIC_FIELDS, ADDITIONAL_DEVICE_FIELDS
|
||||
from .coordinator import PollingCoordinator
|
||||
from .utils import unique_id_loggable
|
||||
from .utils import unique_id_loggable, build_device
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@@ -31,10 +31,10 @@ from bluetti_mqtt.mqtt_client import (
|
||||
MqttFieldType,
|
||||
)
|
||||
|
||||
from . import device_info as dev_info, get_unique_id, build_device
|
||||
from . import device_info as dev_info, get_unique_id
|
||||
from .const import CONTROL_FIELDS, DATA_COORDINATOR, DOMAIN, ADDITIONAL_DEVICE_FIELDS
|
||||
from .coordinator import PollingCoordinator
|
||||
from .utils import mac_loggable, unique_id_loggable
|
||||
from .utils import mac_loggable, unique_id_loggable, build_device
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@@ -1,4 +1,14 @@
|
||||
{
|
||||
"config": {
|
||||
"step": {
|
||||
"user": {
|
||||
"data": {
|
||||
"address": "Gerät",
|
||||
"type": "Modell (erforderlich bei PBOX Geräten)"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"options": {
|
||||
"step": {
|
||||
"init": {
|
||||
|
||||
@@ -1,4 +1,14 @@
|
||||
{
|
||||
"config": {
|
||||
"step": {
|
||||
"user": {
|
||||
"data": {
|
||||
"address": "Device",
|
||||
"type": "Model (required for PBOX devices)"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"options": {
|
||||
"step": {
|
||||
"init": {
|
||||
|
||||
@@ -1,5 +1,11 @@
|
||||
"""Tools."""
|
||||
|
||||
from bluetti_mqtt.bluetooth import build_device as orig_build_device
|
||||
|
||||
from .const import DEVICE_NAME_RE
|
||||
from .devices.ep600 import EP600
|
||||
from .devices.ep760 import EP760
|
||||
|
||||
def mac_loggable(mac: str) -> str:
|
||||
"""Remove parts of the mac address for logging."""
|
||||
splitted = mac.split(":")
|
||||
@@ -10,3 +16,12 @@ def unique_id_loggable(unique_id: str) -> str:
|
||||
splitted = unique_id.split("_", maxsplit=1)
|
||||
serial = splitted[0][:6]
|
||||
return serial + "XXXXXXXXXX" + splitted[1]
|
||||
|
||||
def build_device(address: str, name: str):
|
||||
match = DEVICE_NAME_RE.match(name)
|
||||
if match[1] == 'EP760':
|
||||
return EP760(address, match[2])
|
||||
elif match[1] == 'EP600':
|
||||
return EP600(address, match[2])
|
||||
else:
|
||||
return orig_build_device(address, name)
|
||||
Reference in new issue
Block a user