added dummy device class to append new fields
This commit is contained in:
1 parent
b7c705f224
commit
12cd2719d2
1 file changed
+42
-2
@@ -1,6 +1,7 @@
|
|||||||
"""Coordinator for Bluetti integration."""
|
"""Coordinator for Bluetti integration."""
|
||||||
|
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
from typing import List
|
||||||
|
|
||||||
import asyncio
|
import asyncio
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
@@ -23,10 +24,46 @@ from bluetti_mqtt.bluetooth import (
|
|||||||
ParseError,
|
ParseError,
|
||||||
build_device,
|
build_device,
|
||||||
)
|
)
|
||||||
|
from bluetti_mqtt.core.devices.bluetti_device import BluettiDevice
|
||||||
|
from bluetti_mqtt.core.commands import ReadHoldingRegisters
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
class DummyDevice(BluettiDevice):
|
||||||
|
"""Dummy device.
|
||||||
|
|
||||||
|
Changes made here are only temporary and should also be
|
||||||
|
contributed to https://github.com/warhammerkid/bluetti_mqtt
|
||||||
|
"""
|
||||||
|
|
||||||
|
def __init__(self, device: BluettiDevice):
|
||||||
|
"""Init dummy device with real device."""
|
||||||
|
self.struct = device.struct
|
||||||
|
super().__init__(device.address, device.type, device.sn)
|
||||||
|
self._parent = device
|
||||||
|
|
||||||
|
@property
|
||||||
|
def polling_commands(self) -> List[ReadHoldingRegisters]:
|
||||||
|
return self._parent.polling_commands
|
||||||
|
|
||||||
|
@property
|
||||||
|
def pack_polling_commands(self) -> List[ReadHoldingRegisters]:
|
||||||
|
return self._parent.pack_logging_commands
|
||||||
|
|
||||||
|
@property
|
||||||
|
def logging_commands(self) -> List[ReadHoldingRegisters]:
|
||||||
|
return self._parent.logging_commands
|
||||||
|
|
||||||
|
@property
|
||||||
|
def pack_logging_commands(self) -> List[ReadHoldingRegisters]:
|
||||||
|
return self._parent.pack_logging_commands
|
||||||
|
|
||||||
|
@property
|
||||||
|
def writable_ranges(self) -> List[range]:
|
||||||
|
return self._parent.writable_ranges
|
||||||
|
|
||||||
|
|
||||||
class PollingCoordinator(DataUpdateCoordinator):
|
class PollingCoordinator(DataUpdateCoordinator):
|
||||||
"""Polling coordinator."""
|
"""Polling coordinator."""
|
||||||
|
|
||||||
@@ -42,7 +79,10 @@ class PollingCoordinator(DataUpdateCoordinator):
|
|||||||
self.notify_future = None
|
self.notify_future = None
|
||||||
self.current_command = None
|
self.current_command = None
|
||||||
self.notify_response = bytearray()
|
self.notify_response = bytearray()
|
||||||
self.bluetti_device = build_device(address, device_name)
|
bluetti_device = build_device(address, device_name)
|
||||||
|
|
||||||
|
# Add or modify device fields
|
||||||
|
self.bluetti_device = DummyDevice(bluetti_device)
|
||||||
|
|
||||||
async def _async_update_data(self):
|
async def _async_update_data(self):
|
||||||
"""Fetch data from API endpoint.
|
"""Fetch data from API endpoint.
|
||||||
@@ -99,7 +139,7 @@ class PollingCoordinator(DataUpdateCoordinator):
|
|||||||
command.starting_address, body
|
command.starting_address, body
|
||||||
)
|
)
|
||||||
|
|
||||||
self.logger.debug("Parsed data: %s", parsed)
|
self.logger.error("Parsed data: %s", parsed)
|
||||||
parsed_data.update(parsed)
|
parsed_data.update(parsed)
|
||||||
|
|
||||||
except TimeoutError:
|
except TimeoutError:
|
||||||
|
|||||||
Reference in new issue
Block a user