Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/clean typing linter #285

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

julesxxl
Copy link
Collaborator

@julesxxl julesxxl commented Feb 6, 2025

That was not easy... So no more errors with ruff check, ruff format, mypy. But there are the TODOs with pylint and two other problems.
Unfortunately, I didn't get it work in HA. Pfff... Anyway, the code is there and since it's not urgent, we'll have to understand what's wrong... So many changes...
(I rebased onto #281.)

Errors in the logs:

2025-02-06 11:32:08.536 WARNING (MainThread) [pymodbus.logging] BinaryPayloadDecoder is deprecated and will be removed in v3.9.0 !
Please use "client.convert_from_registers()" or "client.convert_to_registers"
See documentation: "https://pymodbus.readthedocs.io/en/latest/source/client.html#pymodbus.client.mixin.ModbusClientMixin.convert_from_registers"
2025-02-06 11:32:08.547 WARNING (MainThread) [pymodbus.logging] BinaryPayloadDecoder is deprecated and will be removed in v3.9.0 !
Please use "client.convert_from_registers()" or "client.convert_to_registers"
See documentation: "https://pymodbus.readthedocs.io/en/latest/source/client.html#pymodbus.client.mixin.ModbusClientMixin.convert_from_registers"
2025-02-06 11:32:08.552 WARNING (MainThread) [pymodbus.logging] BinaryPayloadDecoder is deprecated and will be removed in v3.9.0 !
Please use "client.convert_from_registers()" or "client.convert_to_registers"
See documentation: "https://pymodbus.readthedocs.io/en/latest/source/client.html#pymodbus.client.mixin.ModbusClientMixin.convert_from_registers"
2025-02-06 11:32:08.552 ERROR (MainThread) [custom_components.victron.coordinator] Unexpected error fetching victron data
Traceback (most recent call last):
  File "/Users/julienpichavant/homeassistant/lib/python3.13/site-packages/homeassistant/helpers/update_coordinator.py", line 380, in _async_refresh
    self.data = await self._async_update_data()
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/julienpichavant/.homeassistant/custom_components/victron/coordinator.py", line 104, in _async_update_data
    self.parse_register_data(
    ~~~~~~~~~~~~~~~~~~~~~~~~^
        data, register_info_dict[name], unit
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    ).items()
    ^
  File "/Users/julienpichavant/.homeassistant/custom_components/victron/coordinator.py", line 155, in parse_register_data
    raise DecodedataTypeUnsupported(
        f"Not supported data_type: {value.data_type}"
    )
custom_components.victron.coordinator.DecodedataTypeUnsupported: Not supported data_type: <custom_components.victron.const.STRING object at 0x11f0c4750>

@sfstar
Copy link
Owner

sfstar commented Feb 6, 2025

Thanks for the PR and effort, wil check out/review this weekend

@sfstar sfstar added enhancement Enhancement of the code, not introducing new features. refactor Improvement of existing code, not introducing new features. maintenance Generic maintenance tasks. labels Feb 6, 2025
@julesxxl
Copy link
Collaborator Author

julesxxl commented Feb 9, 2025

OK. Fixed those ones and others. 👍

@sfstar
Copy link
Owner

sfstar commented Feb 12, 2025

Great, wasn't able to finish the review this weekend.
Will look at the latest changes in the coming couple days

Copy link
Owner

@sfstar sfstar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the PR @julesxxl.

I've added feedback and questions as they arose.
Once they have been processed I will run this version locally and do a final lookover.

Keep up the good work :)

config = dict(self.config_entry.options)
user_input.pop(CONF_RESCAN, None)
if user_input:
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO's run this locally and go through config flow

@@ -75,100 +76,111 @@ def __init__(self, length=1, read_length=None):


class EntityType:
"""Base entityType."""
"""Base entity_type."""
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

EntityType is an class here and should therefore not be renamed in the comment from class style to var style

super().__init__(entity_type_name=entity_type_name)


class GenericAlarmLedger(Enum):
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this removed elsewhere?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed from line 180 probably due to the use of class on 166 and needing to be declared before used

@@ -207,7 +211,7 @@ class generic_alarm_ledger(Enum):
"grid_L3_energy_reverse": RegisterInfo(
2608, UINT16, UnitOfEnergy.KILO_WATT_HOUR, 100
),
"grid_serial": RegisterInfo(2609, STRING(7)),
"grid_serial": RegisterInfo(2609, str(STRING(7))),
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why cast the string as an str here?

),
"battery_error": RegisterInfo(
register=1283, dataType=UINT16, entityType=TextReadEntityType(battery_error)
"BatteryError": RegisterInfo(
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use batteryError here since generic Alarm ledger doesn't do the same as the battery error enum class

first_register = next(iter(registerInfoDict))
return registerInfoDict[first_register].register
first_register = next(iter(register_infoDict))
return register_infoDict[first_register].register
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should the name be register_info_dict to conform to convention?

if self.description.key:
full_key = str(self.description.slave) + "." + self.description.key
else:
full_key = str(self.description.slave) + "."
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this returns an invalid entity_id.

from typing import Any


class PopBuffer:
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ignored in review as it is still being written

@@ -120,7 +123,7 @@ def determine_victron_device_class(name, unit):
SensorDeviceClass.VOLUME_STORAGE
) # Perhaps change this to water if only water is measured in volume units
if unit in [member.value for member in UnitOfSpeed]:
if "meteo" in name:
if name and "meteo" in name:
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add seperate check for name to exist and not check 2 times in different if statements.

self._attr_native_value = self.entity_type.decodeEnum(
if data in {
item.value # type: ignore[union-attr]
for item in self.entity_type.entity_type_name
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

has the decode enum been replaced?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Enhancement of the code, not introducing new features. maintenance Generic maintenance tasks. refactor Improvement of existing code, not introducing new features.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants