Skip to content
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
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2207,7 +2207,7 @@ For information on how to add, remove, and configure devices, please refer to th
- Wireless Warning Code _(disabled)_
- LED Brightness _(disabled)_
- Heartbeat Frequency _(disabled)_
- Status (Scheduled)
- Status

*Sliders (numbers)*
- Min Discharge Level
Expand Down Expand Up @@ -2966,7 +2966,6 @@ For information on how to add, remove, and configure devices, please refer to th
- mpptPv2.pwr
- mpptPv2.amp
- mpptPv2.vol
- Status (Scheduled)
- Status

</p></details>

38 changes: 37 additions & 1 deletion custom_components/ecoflow_cloud/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@
from homeassistant.const import Platform
from homeassistant.core import HomeAssistant
from homeassistant.exceptions import ConfigEntryNotReady
from homeassistant.helpers import entity_registry as er

from . import _preload_proto # noqa: F401 # pyright: ignore[reportUnusedImport]
from .device_data import DeviceData, DeviceOptions

_LOGGER = logging.getLogger(__name__)

ECOFLOW_DOMAIN = "ecoflow_cloud"
CONFIG_VERSION = 10
CONFIG_VERSION = 11

_PLATFORMS = {
Platform.BINARY_SENSOR,
Expand Down Expand Up @@ -66,6 +67,23 @@
_STATUS_COORDINATOR_KEY = "__status_coordinator"


def _migrate_entity_unique_id(
hass: HomeAssistant,
platform: Platform,
old_unique_id: str,
new_unique_id: str,
) -> bool:
registry = er.async_get(hass)
entity_id = registry.async_get_entity_id(platform, ECOFLOW_DOMAIN, old_unique_id)
if entity_id is None:
return False
if registry.async_get_entity_id(platform, ECOFLOW_DOMAIN, new_unique_id) is not None:
return False

registry.async_update_entity(entity_id, new_unique_id=new_unique_id)
return True


async def async_migrate_entry(hass: HomeAssistant, config_entry: ConfigEntry):
updated: bool = False
if config_entry.version in (5, 6):
Expand Down Expand Up @@ -137,6 +155,24 @@ async def async_migrate_entry(hass: HomeAssistant, config_entry: ConfigEntry):
updated = hass.config_entries.async_update_entry(config_entry, version=10, options=new_options)
_LOGGER.info("Config entries updated to version %d", config_entry.version)

if config_entry.version == 10:
if CONF_ACCESS_KEY in config_entry.data:
for sn, device_info in config_entry.data[CONF_DEVICE_LIST].items():
if device_info[CONF_DEVICE_TYPE] not in ("PowerStream", "Power Ocean"):
continue

migrated = _migrate_entity_unique_id(
hass,
Platform.SENSOR,
f"ecoflow-api-{sn}-status-scheduled",
f"ecoflow-api-{sn}-status",
)
if migrated:
_LOGGER.info("Migrated scheduled status entity unique ID for %s", sn)

updated = hass.config_entries.async_update_entry(config_entry, version=11)
_LOGGER.info("Config entries updated to version %d", config_entry.version)

return updated


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ def _prepare_data(self, raw_data) -> dict[str, Any]:

def _status_sensor(self, client: EcoflowApiClient) -> QuotaScheduledStatusSensorEntity:
# Keep quota fallback active even while MQTT stream is sparse.
return QuotaScheduledStatusSensorEntity(client, self, 60)
return QuotaScheduledStatusSensorEntity(client, self, 60, "Status", "status")

def _flatten_param_branch(self, prefix: str, value: Any, target: dict[str, Any]) -> None:
if isinstance(value, dict):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,4 +195,4 @@ def _prepare_data(self, raw_data: bytes) -> dict[str, Any]:

def _status_sensor(self, client: EcoflowApiClient) -> QuotaScheduledStatusSensorEntity:
# Keep quota fallback active even while MQTT stream is sparse.
return QuotaScheduledStatusSensorEntity(client, self, 60)
return QuotaScheduledStatusSensorEntity(client, self, 60, "Status", "status")
11 changes: 9 additions & 2 deletions custom_components/ecoflow_cloud/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -580,8 +580,15 @@ def __init__(
class QuotaScheduledStatusSensorEntity(QuotaStatusSensorEntity):
"""QuotaStatusSensorEntity with additional periodic scheduled refresh."""

def __init__(self, client: EcoflowApiClient, device: BaseDevice, reload_delay: int = 3600):
super().__init__(client, device, "Status (Scheduled)", "status.scheduled")
def __init__(
self,
client: EcoflowApiClient,
device: BaseDevice,
reload_delay: int = 3600,
title: str = "Status (Scheduled)",
key: str = "status.scheduled",
):
super().__init__(client, device, title, key)
self._scheduled_refresh_sec = reload_delay


Expand Down
3 changes: 1 addition & 2 deletions docs/devices/PowerStream-Public.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
- Wireless Warning Code (`20_1.wirelessWarnCode`) _(disabled)_
- LED Brightness (`20_1.invBrightness`) _(disabled)_
- Heartbeat Frequency (`20_1.heartbeatFrequency`) _(disabled)_
- Status (Scheduled)
- Status

*Sliders (numbers)*
- Min Discharge Level (`20_1.lowerLimit` -> `{"sn": "SN", "cmdCode": "WN511_SET_BAT_LOWER_PACK", "params": {"lowerLimit": "VALUE"}}` [0 - 30])
Expand All @@ -69,4 +69,3 @@
*Selects*
- Power supply mode (`20_1.supplyPriority` -> `{"sn": "SN", "cmdCode": "WN511_SET_SUPPLY_PRIORITY_PACK", "params": {"supplyPriority": "VALUE"}}` [Prioritize power supply (0), Prioritize power storage (1)])


3 changes: 1 addition & 2 deletions docs/devices/Power_Ocean-Public.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,5 @@
- mpptPv2.pwr (`96_1.mpptHeartBeat[0].mpptPv[1].pwr`)
- mpptPv2.amp (`96_1.mpptHeartBeat[0].mpptPv[1].amp`)
- mpptPv2.vol (`96_1.mpptHeartBeat[0].mpptPv[1].vol`)
- Status (Scheduled)

- Status

5 changes: 2 additions & 3 deletions docs/summary.md
Original file line number Diff line number Diff line change
Expand Up @@ -2168,7 +2168,7 @@
- Wireless Warning Code _(disabled)_
- LED Brightness _(disabled)_
- Heartbeat Frequency _(disabled)_
- Status (Scheduled)
- Status

*Sliders (numbers)*
- Min Discharge Level
Expand Down Expand Up @@ -2927,8 +2927,7 @@
- mpptPv2.pwr
- mpptPv2.amp
- mpptPv2.vol
- Status (Scheduled)
- Status

</p></details>


Loading