-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
240 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,8 @@ | |
Platform.SELECT, | ||
Platform.SENSOR, | ||
Platform.SWITCH, | ||
Platform.BUTTON, | ||
|
||
} | ||
|
||
ATTR_STATUS_SN = "SN" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import logging | ||
from typing import Any | ||
|
||
from homeassistant.config_entries import ConfigEntry | ||
from homeassistant.core import HomeAssistant | ||
from homeassistant.helpers.entity import EntityCategory | ||
from homeassistant.helpers.entity_platform import AddEntitiesCallback | ||
|
||
from . import DOMAIN | ||
from .entities import BaseButtonEntity | ||
from .mqtt.ecoflow_mqtt import EcoflowMQTTClient | ||
|
||
_LOGGER = logging.getLogger(__name__) | ||
|
||
|
||
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback): | ||
client: EcoflowMQTTClient = hass.data[DOMAIN][entry.entry_id] | ||
|
||
from .devices.registry import devices | ||
async_add_entities(devices[client.device_type].buttons(client)) | ||
|
||
|
||
class EnabledButtonEntity(BaseButtonEntity): | ||
|
||
def press(self, **kwargs: Any) -> None: | ||
if self._command: | ||
self.send_set_message(0, self.command_dict(0)) | ||
|
||
class DisabledButtonEntity(BaseButtonEntity): | ||
|
||
async def async_press(self, **kwargs: Any) -> None: | ||
if self._command: | ||
self.send_set_message(0, self.command_dict(0)) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
from homeassistant.const import Platform | ||
|
||
from . import const, BaseDevice, EntityMigration, MigrationAction | ||
from .const import ATTR_DESIGN_CAPACITY, ATTR_FULL_CAPACITY, ATTR_REMAIN_CAPACITY, BATTERY_CHARGING_STATE | ||
from ..entities import BaseSensorEntity, BaseNumberEntity, BaseSwitchEntity, BaseSelectEntity, BaseButtonEntity | ||
from ..mqtt.ecoflow_mqtt import EcoflowMQTTClient | ||
from ..number import ChargingPowerEntity, MaxBatteryLevelEntity, MinBatteryLevelEntity, SetTempEntity | ||
from ..select import DictSelectEntity, TimeoutDictSelectEntity | ||
from ..sensor import LevelSensorEntity, RemainSensorEntity, SecondsRemainSensorEntity, TempSensorEntity, \ | ||
CyclesSensorEntity, InWattsSensorEntity, OutWattsSensorEntity, VoltSensorEntity, QuotasStatusSensorEntity, \ | ||
MilliVoltSensorEntity, InMilliVoltSensorEntity, OutMilliVoltSensorEntity, ChargingStateSensorEntity, \ | ||
FanSensorEntity, MiscBinarySensorEntity, DecicelsiusSensorEntity, MiscSensorEntity | ||
from ..switch import EnabledEntity | ||
from ..button import EnabledButtonEntity | ||
|
||
|
||
class Glacier(BaseDevice): | ||
def charging_power_step(self) -> int: | ||
return 50 | ||
|
||
def sensors(self, client: EcoflowMQTTClient) -> list[BaseSensorEntity]: | ||
return [ | ||
# Power and Battery Entities | ||
LevelSensorEntity(client, "bms_bmsStatus.soc", const.MAIN_BATTERY_LEVEL) | ||
.attr("bms_bmsStatus.designCap", ATTR_DESIGN_CAPACITY, 0) | ||
.attr("bms_bmsStatus.fullCap", ATTR_FULL_CAPACITY, 0) | ||
.attr("bms_bmsStatus.remainCap", ATTR_REMAIN_CAPACITY, 0), | ||
|
||
LevelSensorEntity(client, "bms_emsStatus.f32LcdSoc", const.COMBINED_BATTERY_LEVEL), | ||
|
||
ChargingStateSensorEntity(client, "bms_emsStatus.chgState", BATTERY_CHARGING_STATE), | ||
|
||
InWattsSensorEntity(client, "bms_bmsStatus.inWatts", const.TOTAL_IN_POWER), | ||
OutWattsSensorEntity(client, "bms_bmsStatus.outWatts", const.TOTAL_OUT_POWER), | ||
|
||
OutWattsSensorEntity(client, "pd.motorWat", "Motor Power"), | ||
|
||
RemainSensorEntity(client, "bms_emsStatus.chgRemain", const.CHARGE_REMAINING_TIME), | ||
RemainSensorEntity(client, "bms_emsStatus.dsgRemain", const.DISCHARGE_REMAINING_TIME), | ||
|
||
CyclesSensorEntity(client, "bms_bmsStatus.cycles", const.CYCLES), | ||
|
||
TempSensorEntity(client, "bms_bmsStatus.tmp", const.BATTERY_TEMP), | ||
TempSensorEntity(client, "bms_bmsStatus.minCellTmp", const.MIN_CELL_TEMP, False), | ||
TempSensorEntity(client, "bms_bmsStatus.maxCellTmp", const.MAX_CELL_TEMP, False), | ||
|
||
VoltSensorEntity(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), | ||
|
||
MiscBinarySensorEntity(client,"pd.batFlag","Battery Present"), | ||
|
||
MiscSensorEntity(client, "pd.xt60InState", "XT60 State"), | ||
|
||
#Fridge Entities | ||
FanSensorEntity(client, "bms_emsStatus.fanLvl", "Fan Level"), | ||
|
||
DecicelsiusSensorEntity(client, "pd.ambientTmp", "Ambient Temperature"), | ||
DecicelsiusSensorEntity(client, "pd.exhaustTmp", "Exhaust Temperature"), | ||
DecicelsiusSensorEntity(client, "pd.tempWater", "Water Temperature"), | ||
DecicelsiusSensorEntity(client, "pd.tmpL", "Left Temperature"), | ||
DecicelsiusSensorEntity(client, "pd.tmpR", "Right Temperature"), | ||
|
||
MiscBinarySensorEntity(client,"pd.flagTwoZone","Dual Zone Mode"), | ||
|
||
SecondsRemainSensorEntity(client, "pd.iceTm", "Ice Time Remain"), | ||
LevelSensorEntity(client, "pd.icePercent", "Ice Percentage"), | ||
|
||
MiscSensorEntity(client, "pd.iceMkMode", "Ice Make Mode"), | ||
|
||
MiscBinarySensorEntity(client,"pd.iceAlert","Ice Alert"), | ||
MiscBinarySensorEntity(client,"pd.waterLine","Ice Water Level OK"), | ||
|
||
QuotasStatusSensorEntity(client) | ||
|
||
] | ||
|
||
def numbers(self, client: EcoflowMQTTClient) -> list[BaseNumberEntity]: | ||
return [ | ||
SetTempEntity(client,"pd.tmpLSet", "Left Set Temperature",-25, 10, | ||
lambda value, params: {"moduleType": 1, "operateType": "temp", | ||
"params": {"tmpM": int(params.get("pd.tmpMSet", 0)), | ||
"tmpL": int(value), | ||
"tmpR": int(params.get("pd.tmpRSet", 0))}}), | ||
|
||
SetTempEntity(client,"pd.tmpMSet", "Combined Set Temperature",-25, 10, | ||
lambda value, params: {"moduleType": 1, "operateType": "temp", | ||
"params": {"tmpM": int(value), | ||
"tmpL": int(params.get("pd.tmpLSet", 0)), | ||
"tmpR": int(params.get("pd.tmpRSet", 0))}}), | ||
|
||
SetTempEntity(client,"pd.tmpRSet", "Right Set Temperature",-25, 10, | ||
lambda value, params: {"moduleType": 1, "operateType": "temp", | ||
"params": {"tmpM": int(params.get("pd.tmpMSet", 0)), | ||
"tmpL": int(params.get("pd.tmpLSet", 0)), | ||
"tmpR": int(value)}}), | ||
|
||
] | ||
|
||
def switches(self, client: EcoflowMQTTClient) -> list[BaseSwitchEntity]: | ||
return [ | ||
|
||
] | ||
|
||
def buttons(self, client: EcoflowMQTTClient) -> list[BaseButtonEntity]: | ||
return [ | ||
EnabledButtonEntity(client, "smlice", "Make Small Ice", lambda value: {"moduleType": 1, "operateType": "iceMake", "params": {"enable": 1, "iceShape": 0}}), | ||
EnabledButtonEntity(client, "lrgice", "Make Large Ice", lambda value: {"moduleType": 1, "operateType": "iceMake", "params": {"enable": 1, "iceShape": 1}}), | ||
EnabledButtonEntity(client, "deice", "Detach Ice", lambda value: {"moduleType": 1, "operateType": "deIce", "params": {"enable": 1}}) | ||
|
||
] | ||
|
||
|
||
def selects(self, client: EcoflowMQTTClient) -> list[BaseSelectEntity]: | ||
return [ | ||
|
||
] | ||
|
||
def migrate(self, version) -> list[EntityMigration]: | ||
if version == 2: | ||
return [ | ||
EntityMigration("pd.soc", Platform.SENSOR, MigrationAction.REMOVE), | ||
] | ||
return [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters