fixed field_attributes dataclasses
This commit is contained in:
1 parent
c45994a9a6
commit
d8999c6470
2 files changed
+78
-39
No files matched your search
@@ -22,61 +22,103 @@ class FieldType(Enum):
|
|||||||
BUTTON = auto()
|
BUTTON = auto()
|
||||||
|
|
||||||
|
|
||||||
@dataclass(frozen=True)
|
|
||||||
class FieldAttributes:
|
class FieldAttributes:
|
||||||
type: FieldType
|
def __init__(
|
||||||
setter: bool = False
|
self,
|
||||||
name: str
|
type: FieldType = FieldType.NUMERIC,
|
||||||
unit_of_measurement: str | None = None
|
setter: bool = False,
|
||||||
device_class: str | None = None
|
name: str = "",
|
||||||
state_class: str | None = None
|
unit_of_measurement: str | None = None,
|
||||||
options: Enum | None = None
|
device_class: str | None = None,
|
||||||
|
state_class: str | None = None,
|
||||||
|
options: Enum | None = None,
|
||||||
|
):
|
||||||
|
self.type = type
|
||||||
|
self.setter = setter
|
||||||
|
self.name = name
|
||||||
|
self.unit_of_measurement = unit_of_measurement
|
||||||
|
self.device_class = device_class
|
||||||
|
self.state_class = state_class
|
||||||
|
self.options = options
|
||||||
|
|
||||||
|
|
||||||
@dataclass(frozen=True)
|
|
||||||
class PowerFieldAttributes(FieldAttributes):
|
class PowerFieldAttributes(FieldAttributes):
|
||||||
type = FieldType.NUMERIC
|
def __init__(
|
||||||
unit_of_measurement = "W"
|
self,
|
||||||
device_class = "power"
|
name: str = "",
|
||||||
state_class = "measurement"
|
):
|
||||||
|
super().__init__(
|
||||||
|
name=name,
|
||||||
|
unit_of_measurement="W",
|
||||||
|
device_class="power",
|
||||||
|
state_class="measurement",
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
|
||||||
class VoltageFieldAttributes(FieldAttributes):
|
class VoltageFieldAttributes(FieldAttributes):
|
||||||
type = FieldType.NUMERIC
|
def __init__(
|
||||||
unit_of_measurement = "V"
|
self,
|
||||||
device_class = "voltage"
|
name: str = "",
|
||||||
state_class = "measurement"
|
):
|
||||||
|
super().__init__(
|
||||||
|
name=name,
|
||||||
|
unit_of_measurement="V",
|
||||||
|
device_class="voltage",
|
||||||
|
state_class="measurement",
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
|
||||||
class CurrentFieldAttributes(FieldAttributes):
|
class CurrentFieldAttributes(FieldAttributes):
|
||||||
type = FieldType.NUMERIC
|
def __init__(
|
||||||
unit_of_measurement = "A"
|
self,
|
||||||
device_class = "current"
|
name: str = "",
|
||||||
state_class = "measurement"
|
):
|
||||||
|
super().__init__(
|
||||||
|
name=name,
|
||||||
|
unit_of_measurement="A",
|
||||||
|
device_class="current",
|
||||||
|
state_class="measurement",
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
|
||||||
class EnergyFieldAttributes(FieldAttributes):
|
class EnergyFieldAttributes(FieldAttributes):
|
||||||
type = FieldType.NUMERIC
|
def __init__(
|
||||||
unit_of_measurement = "kWh"
|
self,
|
||||||
device_class = "energy"
|
name: str = "",
|
||||||
state_class = "total_increasing"
|
):
|
||||||
|
super().__init__(
|
||||||
|
name=name,
|
||||||
|
unit_of_measurement="kWh",
|
||||||
|
device_class="energy",
|
||||||
|
state_class="total_increasing",
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
|
||||||
class FrequencyFieldAttributes(FieldAttributes):
|
class FrequencyFieldAttributes(FieldAttributes):
|
||||||
type = (FieldType.NUMERIC,)
|
def __init__(
|
||||||
unit_of_measurement = ("Hz",)
|
self,
|
||||||
device_class = ("frequency",)
|
name: str = "",
|
||||||
state_class = ("measurement",)
|
):
|
||||||
|
super().__init__(
|
||||||
|
name=name,
|
||||||
|
unit_of_measurement="Hz",
|
||||||
|
device_class="frequency",
|
||||||
|
state_class="measurement",
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
@dataclass(frozen=True)
|
|
||||||
class OutletFieldAttributes(FieldAttributes):
|
class OutletFieldAttributes(FieldAttributes):
|
||||||
type = FieldType.BOOL
|
def __init__(
|
||||||
device_class = "outlet"
|
self,
|
||||||
|
name: str = "",
|
||||||
|
setter: bool = False,
|
||||||
|
):
|
||||||
|
super().__init__(
|
||||||
|
type=FieldType.BOOL,
|
||||||
|
name=name,
|
||||||
|
setter=setter,
|
||||||
|
device_class="outlet",
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
FIELD_ATTRIBUTES: dict[str, FieldAttributes] = {
|
FIELD_ATTRIBUTES: dict[str, FieldAttributes] = {
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
"""Constants for the Bluetti BT integration."""
|
"""Constants for the Bluetti BT integration."""
|
||||||
|
|
||||||
import re
|
|
||||||
|
|
||||||
DOMAIN = "bluetti_bt"
|
DOMAIN = "bluetti_bt"
|
||||||
MANUFACTURER = "Bluetti"
|
MANUFACTURER = "Bluetti"
|
||||||
|
|
||||||
@@ -26,7 +24,6 @@ SUPPORTED_MODELS = [
|
|||||||
"EP600",
|
"EP600",
|
||||||
"EP760",
|
"EP760",
|
||||||
]
|
]
|
||||||
DEVICE_NAME_RE = re.compile(r'^(AC200M|AC300|AC500|AC60|EP500P|EP500|EP600|EP760|EB3A)(\d+)$')
|
|
||||||
|
|
||||||
CONTROL_FIELDS = [
|
CONTROL_FIELDS = [
|
||||||
"ac_output_on",
|
"ac_output_on",
|
||||||
|
|||||||
Reference in new issue
Block a user