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

Make static modbus entity values classvar defaults #136488

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from
Open
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
9 changes: 5 additions & 4 deletions homeassistant/components/modbus/entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,11 @@
class BasePlatform(Entity):
"""Base for readonly platforms."""

_value: str | None = None
_attr_should_poll = False
_attr_available = True
_attr_unit_of_measurement = None

def __init__(
self, hass: HomeAssistant, hub: ModbusHub, entry: dict[str, Any]
) -> None:
Expand All @@ -86,18 +91,14 @@ def __init__(
self._slave = entry.get(CONF_DEVICE_ADDRESS, 1)
self._address = int(entry[CONF_ADDRESS])
self._input_type = entry[CONF_INPUT_TYPE]
self._value: str | None = None
self._scan_interval = int(entry[CONF_SCAN_INTERVAL])
self._call_active = False
self._cancel_timer: Callable[[], None] | None = None
self._cancel_call: Callable[[], None] | None = None

self._attr_unique_id = entry.get(CONF_UNIQUE_ID)
self._attr_name = entry[CONF_NAME]
self._attr_should_poll = False
self._attr_device_class = entry.get(CONF_DEVICE_CLASS)
self._attr_available = True
self._attr_unit_of_measurement = None

def get_optional_numeric_config(config_name: str) -> int | float | None:
if (val := entry.get(config_name)) is None:
Expand Down