Skip to content

Commit

Permalink
Add controls for pre-FB00 HMI
Browse files Browse the repository at this point in the history
  • Loading branch information
fboundy committed Nov 28, 2024
1 parent 331d599 commit 5df9e50
Show file tree
Hide file tree
Showing 9 changed files with 992 additions and 157 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ As you might have noticed I'm having trouble to spend enough time on maintaining

# Control Beta Test

This repo includes a beta version of device control using the same API as the SolisCloud app. This opeartes slighty differently depending on your HMI firmware version. This should be detected automatically:
This repo includes a beta version of device control using the same API as the SolisCloud app. This opeartes slighty differently depending on your HMI firmware version. This should be detected automatically.

Please report any issues via https://github.com/fboundy/solis-sensor/issues

## Version 4A00 and Earlier

Expand Down
13 changes: 12 additions & 1 deletion custom_components/solis/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,13 @@
Platform.BUTTON,
]

CONTROL_PLATFORMS = [
Platform.SELECT,
Platform.NUMBER,
Platform.TIME,
Platform.BUTTON,
]


async def async_setup(hass: HomeAssistant, config: ConfigType):
"""Set up the Solis component from configuration.yaml."""
Expand Down Expand Up @@ -93,7 +100,11 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
hass.data[DOMAIN][entry.entry_id] = service

# Forward the setup to the sensor platform.
await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
await hass.config_entries.async_forward_entry_setups(entry, [Platform.SENSOR])
# while not service.discovery_complete:
# asyncio.sleep(1)
_LOGGER.debug("Sensor setup complete")
await hass.config_entries.async_forward_entry_setups(entry, CONTROL_PLATFORMS)
return True


Expand Down
44 changes: 16 additions & 28 deletions custom_components/solis/button.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry, asyn
_LOGGER.debug(f"Domain: {DOMAIN}")
service = hass.data[DOMAIN][config_entry.entry_id]

_LOGGER.info(f"Waiting for discovery of Button entities for plant {plant_id}")
_LOGGER.info(f"Waiting for discovery of controls for plant {plant_id}")
await asyncio.sleep(8)
attempts = 0
while (attempts < RETRIES) and (not service.has_controls):
Expand All @@ -37,32 +37,18 @@ async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry, asyn
if service.has_controls:
entities = []
_LOGGER.debug(f"Plant ID {plant_id} has controls:")
_LOGGER.debug(service.controls)
for inverter_sn in service.controls:
_LOGGER.debug(f"Waiting for inverter {inverter_sn} HMI status")
attempts = 0
while service.api._hmi_fb00[inverter_sn] is None:
_LOGGER.debug(f" Attempt {attempts} failed")
await asyncio.sleep(RETRY_WAIT)
attempts += 1
hmi_fb00 = service.api._hmi_fb00[inverter_sn]
_LOGGER.debug(f"Inverter SN {inverter_sn} HMI status {hmi_fb00}")
for cid in service.controls[inverter_sn]:
_LOGGER.debug(f">>> {cid:4s}")
for index, entity in enumerate(ALL_CONTROLS[hmi_fb00][cid]):
_LOGGER.debug(f">>> {index} {entity.name} {isinstance(entity, SolisButtonEntityDescription)}")
if isinstance(entity, SolisButtonEntityDescription):
_LOGGER.debug(f"Adding Button entity {entity.name} for inverter Sn {inverter_sn} cid {cid}")
entities.append(
SolisButtonEntity(
service,
config_entry.data["name"],
inverter_sn,
cid,
entity,
index,
)
)
for cid, index, entity, button, intial_value in service.controls[inverter_sn]["button"]:
entities.append(
SolisButtonEntity(
service,
config_entry.data["name"],
inverter_sn,
cid,
entity,
index,
)
)

if len(entities) > 0:
_LOGGER.debug(f"Creating {len(entities)} Button entities")
Expand Down Expand Up @@ -94,6 +80,8 @@ async def async_press(self) -> None:
"""Handle the button press."""
for entity in self._entities:
_LOGGER.debug(f"{entity.name:s} {entity.to_string:s} {entity.index}")
value = self. _joiner.join([entity.to_string for entity in self._entities])
# Sort the entities by their index
items = sorted({entity.index: entity.to_string for entity in self._entities}.items())
value = self._joiner.join([x[1] for x in items])
_LOGGER.debug(f"{self._cid} {value}")
await self.write_control_data(value)
await self.write_control_data(value)
Loading

0 comments on commit 5df9e50

Please sign in to comment.