Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
alexdelprete committed Jan 13, 2025
2 parents 3a41442 + 89e6a7c commit 605b6d5
Show file tree
Hide file tree
Showing 10 changed files with 68 additions and 25 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/dbautomerge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
steps:
- name: Dependabot metadata
id: metadata
uses: dependabot/fetch-metadata@v1
uses: dependabot/fetch-metadata@v2
with:
github-token: "${{ secrets.GITHUB_TOKEN }}"
- name: Auto-merge changes from Dependabot
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ jobs:

steps:
- name: "Checkout the repository"
uses: "actions/[email protected].1"
uses: "actions/[email protected].2"
with:
token: ${{ secrets.WORKFLOW_PAT || github.token }}
ref: ${{ github.head_ref }}

- name: "Set up Python"
uses: actions/setup-python@v5.2.0
uses: actions/setup-python@v5.3.0
with:
python-version: "3.11"
cache: "pip"
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
contents: write
steps:
- name: "Checkout the repository"
uses: "actions/[email protected].1"
uses: "actions/[email protected].2"
with:
token: ${{ secrets.WORKFLOW_PAT || github.token }}

Expand All @@ -32,6 +32,6 @@ jobs:
zip 4noks_elios4you.zip -r ./
- name: "Upload the ZIP file to the release"
uses: softprops/action-gh-release@v2.0.8
uses: softprops/action-gh-release@v2.2.1
with:
files: ${{ github.workspace }}/custom_components/4noks_elios4you/4noks_elios4you.zip
4 changes: 2 additions & 2 deletions .github/workflows/validate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
runs-on: "ubuntu-latest"
steps:
- name: "Checkout the repository"
uses: "actions/[email protected].1"
uses: "actions/[email protected].2"
with:
token: ${{ secrets.WORKFLOW_PAT || github.token }}
ref: ${{ github.head_ref }}
Expand All @@ -26,7 +26,7 @@ jobs:
runs-on: "ubuntu-latest"
steps:
- name: "Checkout the repository"
uses: "actions/[email protected].1"
uses: "actions/[email protected].2"
with:
token: ${{ secrets.WORKFLOW_PAT || github.token }}
ref: ${{ github.head_ref }}
Expand Down
9 changes: 5 additions & 4 deletions .ruff.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

target-version = "py311"

[lint]
select = [
"B007", # Loop control variable {name} not used within loop body
"B014", # Exception handler with duplicate exception
Expand Down Expand Up @@ -57,11 +58,11 @@ ignore = [
"PLE0605",
]

[flake8-pytest-style]
[lint.flake8-pytest-style]
fixture-parentheses = false

[pyupgrade]
[lint.pyupgrade]
keep-runtime-typing = true

[mccabe]
max-complexity = 25
[lint.mccabe]
max-complexity = 25
25 changes: 16 additions & 9 deletions custom_components/4noks_elios4you/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,13 +194,17 @@ async def async_get_data(self):
for key, value in dat_parsed.items():
# @dat returns only numbers as strings
# power/energy as float all others as int
if ("energy" in key) or ("power" in key):
self.data[key] = round(float(value), 2)
# don't create a utc_time sensor
elif key == "utc_time":
pass
else:
self.data[key] = int(value)
try:
if ("energy" in key) or ("power" in key):
self.data[key] = round(float(value), 2)
elif key == "utc_time":
pass
else:
self.data[key] = int(value)
except ValueError:
# If the value cannot be converted to int, log it and skip
_LOGGER.debug(f"async_get_data: Value for {key} could not be parsed to int: {value}")
continue # Skip the invalid value
else:
_LOGGER.debug("async_get_data (ERROR): @dat data is None")

Expand All @@ -209,7 +213,10 @@ async def async_get_data(self):
_LOGGER.debug("async_get_data (WARNING): parsing @sta data")
for key, value in sta_parsed.items():
# @sta returns only float numbers as strings
self.data[key] = round(float(value), 2)
try:
self.data[key] = round(float(value), 2)
except ValueError:
_LOGGER.debug(f"async_get_data: Value for {key} could not be parsed to float: {value}")
else:
_LOGGER.debug("async_get_data (ERROR): @sta data is None")

Expand All @@ -223,7 +230,7 @@ async def async_get_data(self):
_LOGGER.debug("async_get_data (ERROR): @inf data is None")

# Calculated sensor to combine TOP/BOTTOM fw versions
self.data["swver"] = f"{self.data["fwtop"]} / {self.data["fwbtm"]}"
self.data["swver"] = f"{self.data['fwtop']} / {self.data['fwbtm']}"

# Calculated sensors for self-consumption sensors
self.data["self_consumed_power"] = round(
Expand Down
2 changes: 1 addition & 1 deletion custom_components/4noks_elios4you/telnetlib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,7 @@ def process_rawq(self):
# We can't offer automatic processing of
# suboptions. Alas, we should not get any
# unless we did a WILL/DO before.
self.msg("IAC %d not recognized" % ord(c))
self.msg(f"IAC {ord(c)} not recognized")
elif len(self.iacseq) == 2:
cmd = self.iacseq[1:2]
self.iacseq = b""
Expand Down
35 changes: 35 additions & 0 deletions custom_components/4noks_elios4you/translations/pt.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"config": {
"step": {
"user": {
"title": "Configuração de Ligação do Elios4You",
"description": "Se precisar de ajuda com a configuração, visite: https://github.com/alexdelprete/ha-4noks-elios4you",
"data": {
"name": "Nome personalizado do dispositivo (usado como prefixo dos sensores)",
"host": "IP ou nome do host",
"port": "Porta TCP",
"scan_interval": "Período de consulta (mín: 30s máx: 600s)"
}
}
},
"error": {
"already_configured": "O dispositivo já está configurado"
},
"abort": {
"already_configured": "O dispositivo já está configurado"
}
},
"options": {
"step": {
"init": {
"title": "Opções de Ligação do Elios4You",
"description": "Definir opções de ligação",
"data": {
"host": "IP ou nome do host",
"port": "Porta TCP",
"scan_interval": "Período de consulta (mín: 30s máx: 600s)"
}
}
}
}
}
2 changes: 1 addition & 1 deletion e4u-client/lib/telnetlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,7 @@ def process_rawq(self):
# We can't offer automatic processing of
# suboptions. Alas, we should not get any
# unless we did a WILL/DO before.
self.msg("IAC %d not recognized" % ord(c))
self.msg(f"IAC {ord(c)} not recognized")
elif len(self.iacseq) == 2:
cmd = self.iacseq[1:2]
self.iacseq = b""
Expand Down
6 changes: 3 additions & 3 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
colorlog==6.8.2
colorlog==6.9.0
homeassistant==2024.1.2
pip>=21.0,<24.3
ruff==0.6.9
pip>=21.0,<24.4
ruff==0.9.1
telnetlib3>=2.0.4

0 comments on commit 605b6d5

Please sign in to comment.