Skip to content

Commit

Permalink
Merge branch 'main' into power-control-block
Browse files Browse the repository at this point in the history
  • Loading branch information
WillCodeForCats committed Nov 29, 2023
2 parents e7e8631 + f664376 commit 83b05f4
Show file tree
Hide file tree
Showing 19 changed files with 414 additions and 331 deletions.
9 changes: 9 additions & 0 deletions .github/dependabot.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,12 @@ updates:
schedule:
interval: weekly
time: "06:00"
- package-ecosystem: "pip"
directory: "/"
schedule:
interval: daily
time: "00:00"
groups:
python-packages:
patterns:
- "*"
2 changes: 1 addition & 1 deletion .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:

steps:
- name: Checkout repository
uses: actions/checkout@v3
uses: actions/checkout@v4

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/hacs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
name: HACS Action
runs-on: "ubuntu-latest"
steps:
- uses: "actions/checkout@v3"
- uses: "actions/checkout@v4"
- name: HACS Action
uses: "hacs/action@main"
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/hassfest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ jobs:
validate:
runs-on: "ubuntu-latest"
steps:
- uses: "actions/checkout@v3"
- uses: "actions/checkout@v4"
- uses: "home-assistant/actions/hassfest@master"
2 changes: 1 addition & 1 deletion .github/workflows/jsoncheck.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: json-syntax-check
uses: limitusus/[email protected]
with:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/python-quality.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: WillCodeForCats/[email protected].1
- uses: actions/checkout@v4
- uses: WillCodeForCats/[email protected].2
with:
python-root-list: "custom_components/solaredge_modbus_multi"
use-flake8: true
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ After rebooting Home Assistant, this integration can be configured through the i
### Required Versions
* Home Assistant 2023.9.1 or newer
* Python 3.11 or newer
* pymodbus 3.5.1 or newer
* pymodbus 3.5.4 or newer

## Specifications
[WillCodeForCats/solaredge-modbus-multi/tree/main/doc](https://github.com/WillCodeForCats/solaredge-modbus-multi/tree/main/doc)
Expand Down
4 changes: 2 additions & 2 deletions custom_components/solaredge_modbus_multi/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,11 +234,11 @@ async def _refresh_modbus_data_with_retry(
_LOGGER.debug(f"No more data refresh attempts (maximum {limit})")
raise ex

_LOGGER.debug(f"Failed data refresh attempt #{attempt}")
_LOGGER.debug(f"Failed data refresh attempt {attempt}")

attempt += 1
_LOGGER.debug(
f"Waiting {wait_ms} ms before data refresh attempt #{attempt}"
f"Waiting {wait_ms} ms before data refresh attempt {attempt}"
)
await asyncio.sleep(wait_ms / 1000)
wait_ms *= wait_ratio
17 changes: 7 additions & 10 deletions custom_components/solaredge_modbus_multi/binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,11 @@ def __init__(self, platform, config_entry, coordinator):

@property
def available(self) -> bool:
return super().available and self._platform.advanced_power_control is True
return (
super().available
and self._platform.advanced_power_control is True
and "I_AdvPwrCtrlEn" in self._platform.decoded_model.keys()
)

@property
def unique_id(self) -> str:
Expand All @@ -85,12 +89,5 @@ def name(self) -> str:
return "Advanced Power Control"

@property
def is_on(self) -> bool | None:
try:
if self._platform.decoded_model["I_AdvPwrCtrlEn"] == 0x1:
return True

return False

except KeyError:
return None
def is_on(self) -> bool:
return self._platform.decoded_model["I_AdvPwrCtrlEn"] == 0x1
32 changes: 20 additions & 12 deletions custom_components/solaredge_modbus_multi/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,27 @@ class StrEnum(str, Enum):
)


class RetrySettings(IntEnum):
"""Retry settings when opening a connection to the inverter fails."""

Time = 800 # first attempt in milliseconds
Ratio = 3 # time multiplier between each attempt
Limit = 5 # number of attempts before failing


class ModbusDefaults(IntEnum):
"""Values to pass to pymodbus"""

Timeout = 3 # Seconds to wait for a modbus response
ReconnectDelay = 0 # Don't use pymodbus reconnect
"""
ReconnectDelay doubles automatically with each unsuccessful connect, from
ReconnectDelay to ReconnectDelayMax.
Set `ReconnectDelay = 0` to avoid automatic reconnection.
Disabled because it didn't work properly with HA Async in PR#360.
"""

Timeout = 3 # Timeout for a request, in seconds.
ReconnectDelay = 0 # Minimum in seconds.milliseconds before reconnecting.
ReconnectDelayMax = 3.0 # Maximum in seconds.milliseconds before reconnecting.


class SolarEdgeTimeouts(IntEnum):
Expand All @@ -55,14 +71,6 @@ class SolarEdgeTimeouts(IntEnum):
Init = 1200


class RetrySettings(IntEnum):
"""Retry settings when opening a connection to the inverter fails."""

Time = 800 # first attempt in milliseconds
Ratio = 3 # time multiplier between each attempt
Limit = 4 # number of attempts before failing


class BatteryLimit(IntEnum):
"""Configure battery limits for input and display validation."""

Expand All @@ -72,8 +80,8 @@ class BatteryLimit(IntEnum):
Amax = 200 # amps
Tmax = 100 # degrees C
Tmin = -30 # degrees C
ChargeMax = 50000 # watts
DischargeMax = 50000 # watts
ChargeMax = 1000000 # watts
DischargeMax = 1000000 # watts


class ConfDefaultInt(IntEnum):
Expand Down
5 changes: 4 additions & 1 deletion custom_components/solaredge_modbus_multi/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ def scale_factor(value: int, sf: int):


def float_to_hex(f):
return hex(struct.unpack("<I", struct.pack("<f", f))[0])
try:
return hex(struct.unpack("<I", struct.pack("<f", f))[0])
except struct.error as e:
raise TypeError(e)


def parse_modbus_string(s: str) -> str:
Expand Down
Loading

0 comments on commit 83b05f4

Please sign in to comment.