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

Fix battery voltage unit #105

Merged
merged 2 commits into from
Jul 29, 2023
Merged
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
14 changes: 7 additions & 7 deletions custom_components/ecoflow_cloud/devices/delta2.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
MaxGenStopLevelEntity, MinGenStartLevelEntity, BatteryBackupLevel
from ..select import DictSelectEntity, TimeoutDictSelectEntity
from ..sensor import LevelSensorEntity, RemainSensorEntity, TempSensorEntity, CyclesSensorEntity, \
InWattsSensorEntity, OutWattsSensorEntity, VoltSensorEntity, QuotasStatusSensorEntity
InWattsSensorEntity, OutWattsSensorEntity, VoltSensorEntity, QuotasStatusSensorEntity, MilliVoltSensorEntity
from ..switch import BeeperEntity, EnabledEntity


Expand Down Expand Up @@ -45,19 +45,19 @@ def sensors(self, client: EcoflowMQTTClient) -> list[BaseSensorEntity]:
TempSensorEntity(client, "bms_bmsStatus.minCellTemp", const.MIN_CELL_TEMP, False),
TempSensorEntity(client, "bms_bmsStatus.maxCellTemp", const.MAX_CELL_TEMP, False),

VoltSensorEntity(client, "bms_bmsStatus.vol", const.BATTERY_VOLT, False),
VoltSensorEntity(client, "bms_bmsStatus.minCellVol", const.MIN_CELL_VOLT, False),
VoltSensorEntity(client, "bms_bmsStatus.maxCellVol", const.MAX_CELL_VOLT, False),
MilliVoltSensorEntity(client, "bms_bmsStatus.vol", const.BATTERY_VOLT, False),
MilliVoltSensorEntity(client, "bms_bmsStatus.minCellVol", const.MIN_CELL_VOLT, False),
MilliVoltSensorEntity(client, "bms_bmsStatus.maxCellVol", const.MAX_CELL_VOLT, False),

# Optional Slave Battery
LevelSensorEntity(client, "bms_slave.soc", const.SLAVE_BATTERY_LEVEL, False, True),
TempSensorEntity(client, "bms_slave.temp", const.SLAVE_BATTERY_TEMP, False, True),
TempSensorEntity(client, "bms_slave.minCellTemp", const.SLAVE_MIN_CELL_TEMP, False),
TempSensorEntity(client, "bms_slave.maxCellTemp", const.SLAVE_MAX_CELL_TEMP, False),

VoltSensorEntity(client, "bms_slave.vol", const.SLAVE_BATTERY_VOLT, False),
VoltSensorEntity(client, "bms_slave.minCellVol", const.SLAVE_MIN_CELL_VOLT, False),
VoltSensorEntity(client, "bms_slave.maxCellVol", const.SLAVE_MAX_CELL_VOLT, False),
MilliVoltSensorEntity(client, "bms_slave.vol", const.SLAVE_BATTERY_VOLT, False),
MilliVoltSensorEntity(client, "bms_slave.minCellVol", const.SLAVE_MIN_CELL_VOLT, False),
MilliVoltSensorEntity(client, "bms_slave.maxCellVol", const.SLAVE_MAX_CELL_VOLT, False),

CyclesSensorEntity(client, "bms_slave.cycles", const.SLAVE_CYCLES, False, True),
InWattsSensorEntity(client, "bms_slave.inputWatts", const.SLAVE_IN_POWER, False, True),
Expand Down
8 changes: 4 additions & 4 deletions custom_components/ecoflow_cloud/devices/delta2_max.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
MaxGenStopLevelEntity, MinGenStartLevelEntity
from ..select import DictSelectEntity, TimeoutDictSelectEntity
from ..sensor import LevelSensorEntity, RemainSensorEntity, TempSensorEntity, CyclesSensorEntity, \
InWattsSensorEntity, OutWattsSensorEntity, VoltSensorEntity, StatusSensorEntity
InWattsSensorEntity, OutWattsSensorEntity, VoltSensorEntity, StatusSensorEntity, MilliVoltSensorEntity
from ..switch import BeeperEntity, EnabledEntity


Expand Down Expand Up @@ -44,9 +44,9 @@ def sensors(self, client: EcoflowMQTTClient) -> list[BaseSensorEntity]:
TempSensorEntity(client, "bms_bmsStatus.minCellTemp", const.MIN_CELL_TEMP, False),
TempSensorEntity(client, "bms_bmsStatus.maxCellTemp", const.MAX_CELL_TEMP, False),

VoltSensorEntity(client, "bms_bmsStatus.vol", const.BATTERY_VOLT, False),
VoltSensorEntity(client, "bms_bmsStatus.minCellVol", const.MIN_CELL_VOLT, False),
VoltSensorEntity(client, "bms_bmsStatus.maxCellVol", const.MAX_CELL_VOLT, False),
MilliVoltSensorEntity(client, "bms_bmsStatus.vol", const.BATTERY_VOLT, False),
MilliVoltSensorEntity(client, "bms_bmsStatus.minCellVol", const.MIN_CELL_VOLT, False),
MilliVoltSensorEntity(client, "bms_bmsStatus.maxCellVol", const.MAX_CELL_VOLT, False),

# Optional Slave Battery
# LevelSensorEntity(client, "bms_slave.soc", const.SLAVE_BATTERY_LEVEL, False, True),
Expand Down
8 changes: 4 additions & 4 deletions custom_components/ecoflow_cloud/devices/delta_max.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
MaxGenStopLevelEntity, MinGenStartLevelEntity
from ..select import DictSelectEntity, TimeoutDictSelectEntity
from ..sensor import LevelSensorEntity, RemainSensorEntity, TempSensorEntity, CyclesSensorEntity, \
InWattsSensorEntity, OutWattsSensorEntity, VoltSensorEntity, StatusSensorEntity
InWattsSensorEntity, OutWattsSensorEntity, VoltSensorEntity, StatusSensorEntity, MilliVoltSensorEntity
from ..switch import BeeperEntity, EnabledEntity


Expand Down Expand Up @@ -45,9 +45,9 @@ def sensors(self, client: EcoflowMQTTClient) -> list[BaseSensorEntity]:
TempSensorEntity(client, "bmsMaster.minCellTemp", const.MIN_CELL_TEMP, False),
TempSensorEntity(client, "bmsMaster.maxCellTemp", const.MAX_CELL_TEMP, False),

VoltSensorEntity(client, "bmsMaster.vol", const.BATTERY_VOLT, False),
VoltSensorEntity(client, "bmsMaster.minCellVol", const.MIN_CELL_VOLT, False),
VoltSensorEntity(client, "bmsMaster.maxCellVol", const.MAX_CELL_VOLT, False),
MilliVoltSensorEntity(client, "bmsMaster.vol", const.BATTERY_VOLT, False),
MilliVoltSensorEntity(client, "bmsMaster.minCellVol", const.MIN_CELL_VOLT, False),
MilliVoltSensorEntity(client, "bmsMaster.maxCellVol", const.MAX_CELL_VOLT, False),

# Optional Slave Battery
#LevelSensorEntity(client, "bms_slave.soc", const.SLAVE_BATTERY_LEVEL, False, True),
Expand Down
11 changes: 6 additions & 5 deletions custom_components/ecoflow_cloud/devices/delta_pro.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
MaxGenStopLevelEntity
from ..select import DictSelectEntity, TimeoutDictSelectEntity
from ..sensor import LevelSensorEntity, WattsSensorEntity, RemainSensorEntity, TempSensorEntity, \
CyclesSensorEntity, InWattsSensorEntity, OutWattsSensorEntity, OutWattsDcSensorEntity, VoltSensorEntity, InWattsSolarSensorEntity, \
StatusSensorEntity, InEnergySensorEntity, OutEnergySensorEntity
CyclesSensorEntity, InWattsSensorEntity, OutWattsSensorEntity, OutWattsDcSensorEntity, VoltSensorEntity, \
InWattsSolarSensorEntity, \
StatusSensorEntity, InEnergySensorEntity, OutEnergySensorEntity, MilliVoltSensorEntity
from ..switch import BeeperEntity, EnabledEntity


Expand Down Expand Up @@ -44,9 +45,9 @@ def sensors(self, client: EcoflowMQTTClient) -> list[BaseSensorEntity]:
TempSensorEntity(client, "bmsMaster.minCellTemp", const.MIN_CELL_TEMP, False),
TempSensorEntity(client, "bmsMaster.maxCellTemp", const.MAX_CELL_TEMP, False),

VoltSensorEntity(client, "bmsMaster.vol", const.BATTERY_VOLT, False),
VoltSensorEntity(client, "bmsMaster.minCellVol", const.MIN_CELL_VOLT, False),
VoltSensorEntity(client, "bmsMaster.maxCellVol", const.MAX_CELL_VOLT, False),
MilliVoltSensorEntity(client, "bmsMaster.vol", const.BATTERY_VOLT, False),
MilliVoltSensorEntity(client, "bmsMaster.minCellVol", const.MIN_CELL_VOLT, False),
MilliVoltSensorEntity(client, "bmsMaster.maxCellVol", const.MAX_CELL_VOLT, False),

# https://github.com/tolwi/hassio-ecoflow-cloud/discussions/87
InEnergySensorEntity(client, "pd.chgSunPower", const.SOLAR_IN_ENERGY),
Expand Down
7 changes: 4 additions & 3 deletions custom_components/ecoflow_cloud/devices/river2.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
from ..number import ChargingPowerEntity, MaxBatteryLevelEntity, MinBatteryLevelEntity
from ..select import DictSelectEntity, TimeoutDictSelectEntity
from ..sensor import LevelSensorEntity, RemainSensorEntity, TempSensorEntity, \
CyclesSensorEntity, InWattsSensorEntity, OutWattsSensorEntity, VoltSensorEntity, StatusSensorEntity
CyclesSensorEntity, InWattsSensorEntity, OutWattsSensorEntity, VoltSensorEntity, StatusSensorEntity, \
MilliVoltSensorEntity
from ..switch import EnabledEntity


Expand Down Expand Up @@ -40,8 +41,8 @@ def sensors(self, client: EcoflowMQTTClient) -> list[BaseSensorEntity]:
TempSensorEntity(client, "bms_bmsStatus.maxCellTemp", const.MAX_CELL_TEMP, False),

VoltSensorEntity(client, "bms_bmsStatus.vol", const.BATTERY_VOLT, False),
VoltSensorEntity(client, "bms_bmsStatus.minCellVol", const.MIN_CELL_VOLT, False),
VoltSensorEntity(client, "bms_bmsStatus.maxCellVol", const.MAX_CELL_VOLT, False),
MilliVoltSensorEntity(client, "bms_bmsStatus.minCellVol", const.MIN_CELL_VOLT, False),
MilliVoltSensorEntity(client, "bms_bmsStatus.maxCellVol", const.MAX_CELL_VOLT, False),

# FanSensorEntity(client, "bms_emsStatus.fanLevel", "Fan Level"),
StatusSensorEntity(client),
Expand Down
6 changes: 3 additions & 3 deletions custom_components/ecoflow_cloud/devices/river2_max.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from ..select import DictSelectEntity, TimeoutDictSelectEntity
from ..sensor import LevelSensorEntity, RemainSensorEntity, TempSensorEntity, \
CyclesSensorEntity, InWattsSensorEntity, OutWattsSensorEntity, VoltSensorEntity, InAmpSensorEntity, \
InVoltSensorEntity, QuotasStatusSensorEntity
InVoltSensorEntity, QuotasStatusSensorEntity, MilliVoltSensorEntity
from ..switch import EnabledEntity


Expand Down Expand Up @@ -45,8 +45,8 @@ def sensors(self, client: EcoflowMQTTClient) -> list[BaseSensorEntity]:
TempSensorEntity(client, "bms_bmsStatus.maxCellTemp", const.MAX_CELL_TEMP, False),

VoltSensorEntity(client, "bms_bmsStatus.vol", const.BATTERY_VOLT, False),
VoltSensorEntity(client, "bms_bmsStatus.minCellVol", const.MIN_CELL_VOLT, False),
VoltSensorEntity(client, "bms_bmsStatus.maxCellVol", const.MAX_CELL_VOLT, False),
MilliVoltSensorEntity(client, "bms_bmsStatus.minCellVol", const.MIN_CELL_VOLT, False),
MilliVoltSensorEntity(client, "bms_bmsStatus.maxCellVol", const.MAX_CELL_VOLT, False),

QuotasStatusSensorEntity(client),
# FanSensorEntity(client, "bms_emsStatus.fanLevel", "Fan Level"),
Expand Down
7 changes: 4 additions & 3 deletions custom_components/ecoflow_cloud/devices/river2_pro.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
from ..number import ChargingPowerEntity, MaxBatteryLevelEntity, MinBatteryLevelEntity
from ..select import DictSelectEntity, TimeoutDictSelectEntity
from ..sensor import LevelSensorEntity, RemainSensorEntity, TempSensorEntity, \
CyclesSensorEntity, InWattsSensorEntity, OutWattsSensorEntity, VoltSensorEntity, QuotasStatusSensorEntity
CyclesSensorEntity, InWattsSensorEntity, OutWattsSensorEntity, VoltSensorEntity, QuotasStatusSensorEntity, \
MilliVoltSensorEntity
from ..switch import EnabledEntity


Expand Down Expand Up @@ -42,8 +43,8 @@ def sensors(self, client: EcoflowMQTTClient) -> list[BaseSensorEntity]:
TempSensorEntity(client, "bms_bmsStatus.maxCellTemp", const.MAX_CELL_TEMP, False),

VoltSensorEntity(client, "bms_bmsStatus.vol", const.BATTERY_VOLT, False),
VoltSensorEntity(client, "bms_bmsStatus.minCellVol", const.MIN_CELL_VOLT, False),
VoltSensorEntity(client, "bms_bmsStatus.maxCellVol", const.MAX_CELL_VOLT, False),
MilliVoltSensorEntity(client, "bms_bmsStatus.minCellVol", const.MIN_CELL_VOLT, False),
MilliVoltSensorEntity(client, "bms_bmsStatus.maxCellVol", const.MAX_CELL_VOLT, False),
# FanSensorEntity(client, "bms_emsStatus.fanLevel", "Fan Level"),

QuotasStatusSensorEntity(client),
Expand Down
15 changes: 8 additions & 7 deletions custom_components/ecoflow_cloud/devices/river_max.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
from ..number import MaxBatteryLevelEntity
from ..select import DictSelectEntity
from ..sensor import LevelSensorEntity, WattsSensorEntity, RemainSensorEntity, TempSensorEntity, \
CyclesSensorEntity, InWattsSensorEntity, OutWattsSensorEntity, VoltSensorEntity, StatusSensorEntity, InEnergySensorEntity, OutEnergySensorEntity
CyclesSensorEntity, InWattsSensorEntity, OutWattsSensorEntity, VoltSensorEntity, StatusSensorEntity, \
InEnergySensorEntity, OutEnergySensorEntity, MilliVoltSensorEntity
from ..switch import EnabledEntity, BeeperEntity


Expand Down Expand Up @@ -33,9 +34,9 @@ def sensors(self, client: EcoflowMQTTClient) -> list[BaseSensorEntity]:
TempSensorEntity(client, "bmsMaster.minCellTemp", const.MIN_CELL_TEMP, False),
TempSensorEntity(client, "bmsMaster.maxCellTemp", const.MAX_CELL_TEMP, False),

VoltSensorEntity(client, "bmsMaster.vol", const.BATTERY_VOLT, False),
VoltSensorEntity(client, "bmsMaster.minCellVol", const.MIN_CELL_VOLT, False),
VoltSensorEntity(client, "bmsMaster.maxCellVol", const.MAX_CELL_VOLT, False),
MilliVoltSensorEntity(client, "bmsMaster.vol", const.BATTERY_VOLT, False),
MilliVoltSensorEntity(client, "bmsMaster.minCellVol", const.MIN_CELL_VOLT, False),
MilliVoltSensorEntity(client, "bmsMaster.maxCellVol", const.MAX_CELL_VOLT, False),

# https://github.com/tolwi/hassio-ecoflow-cloud/discussions/87
InEnergySensorEntity(client, "pd.chgSunPower", const.SOLAR_IN_ENERGY),
Expand All @@ -50,9 +51,9 @@ def sensors(self, client: EcoflowMQTTClient) -> list[BaseSensorEntity]:
TempSensorEntity(client, "bmsSlave1.minCellTemp", const.SLAVE_MIN_CELL_TEMP, False),
TempSensorEntity(client, "bmsSlave1.maxCellTemp", const.SLAVE_MAX_CELL_TEMP, False),

VoltSensorEntity(client, "bmsSlave1.vol", const.BATTERY_VOLT, False),
VoltSensorEntity(client, "bmsSlave1.minCellVol", const.MIN_CELL_VOLT, False),
VoltSensorEntity(client, "bmsSlave1.maxCellVol", const.MAX_CELL_VOLT, False),
MilliVoltSensorEntity(client, "bmsSlave1.vol", const.BATTERY_VOLT, False),
MilliVoltSensorEntity(client, "bmsSlave1.minCellVol", const.MIN_CELL_VOLT, False),
MilliVoltSensorEntity(client, "bmsSlave1.maxCellVol", const.MAX_CELL_VOLT, False),

CyclesSensorEntity(client, "bmsSlave1.cycles", const.SLAVE_CYCLES, False, True),
StatusSensorEntity(client),
Expand Down
14 changes: 7 additions & 7 deletions custom_components/ecoflow_cloud/devices/river_pro.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from ..select import DictSelectEntity
from ..sensor import LevelSensorEntity, WattsSensorEntity, RemainSensorEntity, TempSensorEntity, \
CyclesSensorEntity, InWattsSensorEntity, OutWattsSensorEntity, VoltSensorEntity, InVoltSensorEntity, \
InAmpSensorEntity, AmpSensorEntity, StatusSensorEntity
InAmpSensorEntity, AmpSensorEntity, StatusSensorEntity, MilliVoltSensorEntity
from ..switch import EnabledEntity, BeeperEntity


Expand Down Expand Up @@ -35,10 +35,10 @@ def sensors(self, client: EcoflowMQTTClient) -> list[BaseSensorEntity]:
TempSensorEntity(client, "bmsMaster.minCellTemp", const.MIN_CELL_TEMP, False),
TempSensorEntity(client, "bmsMaster.maxCellTemp", const.MAX_CELL_TEMP, False),

VoltSensorEntity(client, "bmsMaster.vol", const.BATTERY_VOLT, False),
MilliVoltSensorEntity(client, "bmsMaster.vol", const.BATTERY_VOLT, False),
AmpSensorEntity(client, "bmsMaster.amp", const.BATTERY_AMP, False),
VoltSensorEntity(client, "bmsMaster.minCellVol", const.MIN_CELL_VOLT, False),
VoltSensorEntity(client, "bmsMaster.maxCellVol", const.MAX_CELL_VOLT, False),
MilliVoltSensorEntity(client, "bmsMaster.minCellVol", const.MIN_CELL_VOLT, False),
MilliVoltSensorEntity(client, "bmsMaster.maxCellVol", const.MAX_CELL_VOLT, False),

CyclesSensorEntity(client, "bmsMaster.cycles", const.CYCLES),

Expand All @@ -47,10 +47,10 @@ def sensors(self, client: EcoflowMQTTClient) -> list[BaseSensorEntity]:
LevelSensorEntity(client, "bmsSlave1.soc", const.SLAVE_BATTERY_LEVEL, False, True),
CyclesSensorEntity(client, "bmsSlave1.cycles", const.SLAVE_CYCLES, False, True),
TempSensorEntity(client, "bmsSlave1.temp", const.SLAVE_BATTERY_TEMP, False, True),
VoltSensorEntity(client, "bmsSlave1.vol", const.SLAVE_BATTERY_VOLT, False),
MilliVoltSensorEntity(client, "bmsSlave1.vol", const.SLAVE_BATTERY_VOLT, False),
AmpSensorEntity(client, "bmsSlave1.amp", const.SLAVE_BATTERY_AMP, False),
VoltSensorEntity(client, "bmsSlave1.minCellVol", const.SLAVE_MIN_CELL_VOLT, False),
VoltSensorEntity(client, "bmsSlave1.maxCellVol", const.SLAVE_MAX_CELL_VOLT, False),
MilliVoltSensorEntity(client, "bmsSlave1.minCellVol", const.SLAVE_MIN_CELL_VOLT, False),
MilliVoltSensorEntity(client, "bmsSlave1.maxCellVol", const.SLAVE_MAX_CELL_VOLT, False),


StatusSensorEntity(client),
Expand Down
1 change: 1 addition & 0 deletions custom_components/ecoflow_cloud/number.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ def _updated(self, data: dict[str, Any]):

class LevelEntity(ValueUpdateEntity):
_attr_native_unit_of_measurement = PERCENTAGE


class MinBatteryLevelEntity(LevelEntity):
_attr_icon = "mdi:battery-charging-10"
Expand Down
13 changes: 12 additions & 1 deletion custom_components/ecoflow_cloud/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,14 @@ def _update_value(self, val: Any) -> bool:


class VoltSensorEntity(BaseSensorEntity):
_attr_device_class = SensorDeviceClass.VOLTAGE
_attr_entity_category = EntityCategory.DIAGNOSTIC
_attr_native_unit_of_measurement = UnitOfElectricPotential.VOLT
_attr_state_class = SensorStateClass.MEASUREMENT
_attr_native_value = 0


class MilliVoltSensorEntity(BaseSensorEntity):
_attr_device_class = SensorDeviceClass.VOLTAGE
_attr_entity_category = EntityCategory.DIAGNOSTIC
_attr_native_unit_of_measurement = UnitOfElectricPotential.MILLIVOLT
Expand Down Expand Up @@ -156,11 +164,14 @@ def _update_value(self, val: Any) -> bool:
class OutWattsSensorEntity(WattsSensorEntity):
_attr_icon = "mdi:transmission-tower-export"


class OutWattsDcSensorEntity(WattsSensorEntity):
_attr_icon = "mdi:transmission-tower-export"

def _update_value(self, val: Any) -> bool:
return super()._update_value(int(val) / 10)



class InVoltSensorEntity(VoltSensorEntity):
_attr_icon = "mdi:transmission-tower-import"

Expand Down
Loading