added pack fields to base devices
This commit is contained in:
1 parent
cac64b40bd
commit
01cb7f35a5
3 files changed
+53
-2
No files matched your search
@@ -27,6 +27,13 @@ class ProtocolV1Device(BluettiDevice):
|
|||||||
# Battery
|
# Battery
|
||||||
self.struct.add_uint_field('total_battery_percent', 43)
|
self.struct.add_uint_field('total_battery_percent', 43)
|
||||||
|
|
||||||
|
# Battery packs
|
||||||
|
self.struct.add_uint_field('pack_num_max', 91) # internal
|
||||||
|
self.struct.add_decimal_field('total_battery_voltage', 92, 1)
|
||||||
|
self.struct.add_uint_field('pack_num', 96) # internal
|
||||||
|
self.struct.add_decimal_field('pack_voltage', 98, 2) # Full pack voltage
|
||||||
|
self.struct.add_uint_field('pack_battery_percent', 99)
|
||||||
|
|
||||||
# Output state
|
# Output state
|
||||||
self.struct.add_bool_field('ac_output_on', 48)
|
self.struct.add_bool_field('ac_output_on', 48)
|
||||||
self.struct.add_bool_field('dc_output_on', 49)
|
self.struct.add_bool_field('dc_output_on', 49)
|
||||||
@@ -42,7 +49,11 @@ class ProtocolV1Device(BluettiDevice):
|
|||||||
return [
|
return [
|
||||||
ReadHoldingRegisters(10, 10),
|
ReadHoldingRegisters(10, 10),
|
||||||
ReadHoldingRegisters(36, 4),
|
ReadHoldingRegisters(36, 4),
|
||||||
|
ReadHoldingRegisters(41, 1),
|
||||||
ReadHoldingRegisters(43, 1),
|
ReadHoldingRegisters(43, 1),
|
||||||
|
ReadHoldingRegisters(91, 2),
|
||||||
|
ReadHoldingRegisters(96, 1),
|
||||||
|
ReadHoldingRegisters(98, 2),
|
||||||
ReadHoldingRegisters(48, 2),
|
ReadHoldingRegisters(48, 2),
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|||||||
@@ -27,6 +27,13 @@ class ProtocolV2Device(BluettiDevice):
|
|||||||
# Battery
|
# Battery
|
||||||
self.struct.add_uint_field('total_battery_percent', 102)
|
self.struct.add_uint_field('total_battery_percent', 102)
|
||||||
|
|
||||||
|
# Battery packs
|
||||||
|
#self.struct.add_uint_field('pack_num_max', ?) # internal
|
||||||
|
#self.struct.add_decimal_field('total_battery_voltage', ?, 1)
|
||||||
|
#self.struct.add_uint_field('pack_num', ?) # internal
|
||||||
|
#self.struct.add_decimal_field('pack_voltage', ?, 2) # Full pack voltage
|
||||||
|
#self.struct.add_uint_field('pack_battery_percent', ?)
|
||||||
|
|
||||||
# Output state
|
# Output state
|
||||||
#self.struct.add_bool_field('ac_output_on', ?)
|
#self.struct.add_bool_field('ac_output_on', ?)
|
||||||
#self.struct.add_bool_field('dc_output_on', ?)
|
#self.struct.add_bool_field('dc_output_on', ?)
|
||||||
@@ -44,6 +51,7 @@ class ProtocolV2Device(BluettiDevice):
|
|||||||
return [
|
return [
|
||||||
ReadHoldingRegisters(110, 6),
|
ReadHoldingRegisters(110, 6),
|
||||||
ReadHoldingRegisters(116, 4),
|
ReadHoldingRegisters(116, 4),
|
||||||
|
ReadHoldingRegisters(154, 1),
|
||||||
ReadHoldingRegisters(102, 1),
|
ReadHoldingRegisters(102, 1),
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|||||||
@@ -24,18 +24,24 @@ class FieldAttributes:
|
|||||||
@dataclass(frozen=True)
|
@dataclass(frozen=True)
|
||||||
class PowerFieldAttributes(FieldAttributes):
|
class PowerFieldAttributes(FieldAttributes):
|
||||||
type = FieldType.NUMERIC
|
type = FieldType.NUMERIC
|
||||||
name: str
|
|
||||||
unit_of_measurement = 'W'
|
unit_of_measurement = 'W'
|
||||||
device_class = 'power'
|
device_class = 'power'
|
||||||
state_class = 'measurement'
|
state_class = 'measurement'
|
||||||
|
|
||||||
|
@dataclass
|
||||||
|
class VoltageFieldAttributes(FieldAttributes):
|
||||||
|
type = FieldType.NUMERIC
|
||||||
|
unit_of_measurement = 'V'
|
||||||
|
device_class = 'voltage'
|
||||||
|
state_class = 'measurement'
|
||||||
|
|
||||||
@dataclass(frozen=True)
|
@dataclass(frozen=True)
|
||||||
class OutletFieldAttributes(FieldAttributes):
|
class OutletFieldAttributes(FieldAttributes):
|
||||||
type = FieldType.BOOL
|
type = FieldType.BOOL
|
||||||
name: str
|
|
||||||
device_class = 'outlet'
|
device_class = 'outlet'
|
||||||
|
|
||||||
FIELD_ATTRIBUTES = {
|
FIELD_ATTRIBUTES = {
|
||||||
|
# Base device fields
|
||||||
'dc_input_power': PowerFieldAttributes(
|
'dc_input_power': PowerFieldAttributes(
|
||||||
name = 'DC Input Power',
|
name = 'DC Input Power',
|
||||||
),
|
),
|
||||||
@@ -48,6 +54,13 @@ FIELD_ATTRIBUTES = {
|
|||||||
'dc_output_power': PowerFieldAttributes(
|
'dc_output_power': PowerFieldAttributes(
|
||||||
name = 'DC Output Power',
|
name = 'DC Output Power',
|
||||||
),
|
),
|
||||||
|
'power_generation': FieldAttributes(
|
||||||
|
type = FieldType.NUMERIC,
|
||||||
|
name = 'Total Power Generation',
|
||||||
|
unit_of_measurement = 'kWh',
|
||||||
|
device_class = 'energy',
|
||||||
|
state_class = 'total_increasing',
|
||||||
|
),
|
||||||
'total_battery_percent': FieldAttributes(
|
'total_battery_percent': FieldAttributes(
|
||||||
type = FieldType.NUMERIC,
|
type = FieldType.NUMERIC,
|
||||||
name = 'Total Battery Percent',
|
name = 'Total Battery Percent',
|
||||||
@@ -55,6 +68,9 @@ FIELD_ATTRIBUTES = {
|
|||||||
device_class ='battery',
|
device_class ='battery',
|
||||||
state_class ='measurement',
|
state_class ='measurement',
|
||||||
),
|
),
|
||||||
|
'total_battery_voltage': VoltageFieldAttributes(
|
||||||
|
name = 'Total Battery Voltage',
|
||||||
|
),
|
||||||
'ac_output_on': OutletFieldAttributes(
|
'ac_output_on': OutletFieldAttributes(
|
||||||
name = 'AC Output',
|
name = 'AC Output',
|
||||||
),
|
),
|
||||||
@@ -69,4 +85,20 @@ FIELD_ATTRIBUTES = {
|
|||||||
name = 'DC Output',
|
name = 'DC Output',
|
||||||
setter = True,
|
setter = True,
|
||||||
),
|
),
|
||||||
|
|
||||||
|
# Device specific fields
|
||||||
|
}
|
||||||
|
|
||||||
|
def PACK_FIELD_ATTRIBUTES(pack: int):
|
||||||
|
return {
|
||||||
|
'pack_voltage': VoltageFieldAttributes(
|
||||||
|
name = f'Battery Pack {pack} Voltage',
|
||||||
|
),
|
||||||
|
'pack_battery_percent': FieldAttributes(
|
||||||
|
type = FieldType,
|
||||||
|
name = f'Battery Pack {pack} Percent',
|
||||||
|
unit_of_measurement = '%',
|
||||||
|
device_class ='battery',
|
||||||
|
state_class ='measurement',
|
||||||
|
),
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user