Skip to content

Commit

Permalink
charging state - enum (unused/charging/discharging) (#146)
Browse files Browse the repository at this point in the history
  • Loading branch information
tolwi authored Sep 14, 2023
1 parent c6504ef commit 16bbad2
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 8 deletions.
4 changes: 2 additions & 2 deletions custom_components/ecoflow_cloud/devices/river2.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from ..select import DictSelectEntity, TimeoutDictSelectEntity
from ..sensor import LevelSensorEntity, RemainSensorEntity, TempSensorEntity, \
CyclesSensorEntity, InWattsSensorEntity, OutWattsSensorEntity, VoltSensorEntity, StatusSensorEntity, \
MilliVoltSensorEntity, InMilliVoltSensorEntity, OutMilliVoltSensorEntity, ChargingBinarySensorEntity
MilliVoltSensorEntity, InMilliVoltSensorEntity, OutMilliVoltSensorEntity, ChargingStateSensorEntity
from ..switch import EnabledEntity


Expand All @@ -25,7 +25,7 @@ def sensors(self, client: EcoflowMQTTClient) -> list[BaseSensorEntity]:

LevelSensorEntity(client, "bms_emsStatus.lcdShowSoc", const.COMBINED_BATTERY_LEVEL),

ChargingBinarySensorEntity(client, "bms_emsStatus.chgState", BATTERY_CHARGING_STATE),
ChargingStateSensorEntity(client, "bms_emsStatus.chgState", BATTERY_CHARGING_STATE),

InWattsSensorEntity(client, "pd.wattsInSum", const.TOTAL_IN_POWER),
OutWattsSensorEntity(client, "pd.wattsOutSum", const.TOTAL_OUT_POWER),
Expand Down
4 changes: 2 additions & 2 deletions custom_components/ecoflow_cloud/devices/river2_max.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from ..sensor import LevelSensorEntity, RemainSensorEntity, TempSensorEntity, \
CyclesSensorEntity, InWattsSensorEntity, OutWattsSensorEntity, VoltSensorEntity, InAmpSensorEntity, \
InVoltSensorEntity, QuotasStatusSensorEntity, MilliVoltSensorEntity, InMilliVoltSensorEntity, \
OutMilliVoltSensorEntity, ChargingBinarySensorEntity
OutMilliVoltSensorEntity, ChargingStateSensorEntity
from ..switch import EnabledEntity


Expand All @@ -27,7 +27,7 @@ def sensors(self, client: EcoflowMQTTClient) -> list[BaseSensorEntity]:

LevelSensorEntity(client, "bms_emsStatus.lcdShowSoc", const.COMBINED_BATTERY_LEVEL),

ChargingBinarySensorEntity(client, "bms_emsStatus.chgState", BATTERY_CHARGING_STATE),
ChargingStateSensorEntity(client, "bms_emsStatus.chgState", BATTERY_CHARGING_STATE),

InWattsSensorEntity(client, "pd.wattsInSum", const.TOTAL_IN_POWER),
OutWattsSensorEntity(client, "pd.wattsOutSum", const.TOTAL_OUT_POWER),
Expand Down
6 changes: 3 additions & 3 deletions custom_components/ecoflow_cloud/devices/river2_pro.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from ..select import DictSelectEntity, TimeoutDictSelectEntity
from ..sensor import LevelSensorEntity, RemainSensorEntity, TempSensorEntity, \
CyclesSensorEntity, InWattsSensorEntity, OutWattsSensorEntity, VoltSensorEntity, QuotasStatusSensorEntity, \
MilliVoltSensorEntity, InMilliVoltSensorEntity, OutMilliVoltSensorEntity, ChargingBinarySensorEntity
MilliVoltSensorEntity, InMilliVoltSensorEntity, OutMilliVoltSensorEntity, ChargingStateSensorEntity
from ..switch import EnabledEntity


Expand All @@ -26,7 +26,7 @@ def sensors(self, client: EcoflowMQTTClient) -> list[BaseSensorEntity]:

LevelSensorEntity(client, "bms_emsStatus.lcdShowSoc", const.COMBINED_BATTERY_LEVEL),

ChargingBinarySensorEntity(client, "bms_emsStatus.chgState", BATTERY_CHARGING_STATE),
ChargingStateSensorEntity(client, "bms_emsStatus.chgState", BATTERY_CHARGING_STATE),

InWattsSensorEntity(client, "pd.wattsInSum", const.TOTAL_IN_POWER),
OutWattsSensorEntity(client, "pd.wattsOutSum", const.TOTAL_OUT_POWER),
Expand Down Expand Up @@ -125,4 +125,4 @@ def migrate(self, version) -> list[EntityMigration]:
return [
EntityMigration("pd.soc", Platform.SENSOR, MigrationAction.REMOVE),
]
return []
return []
13 changes: 12 additions & 1 deletion custom_components/ecoflow_cloud/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,21 @@ def _update_value(self, val: Any) -> bool:
return True


class ChargingBinarySensorEntity(MiscBinarySensorEntity):
class ChargingStateSensorEntity(BaseSensorEntity):
_attr_entity_category = EntityCategory.DIAGNOSTIC
_attr_icon = "mdi:battery-charging"
_attr_device_class = BinarySensorDeviceClass.BATTERY_CHARGING

def _update_value(self, val: Any) -> bool:
if val == 0:
return super()._update_value("unused")
elif val == 1:
return super()._update_value("charging")
elif val == 2:
return super()._update_value("discharging")
else:
return False


class CyclesSensorEntity(BaseSensorEntity):
_attr_entity_category = EntityCategory.DIAGNOSTIC
Expand Down

0 comments on commit 16bbad2

Please sign in to comment.