Skip to content

Commit c69c237

Browse files
committed
Align with core changes
1 parent 4ee8c18 commit c69c237

4 files changed

Lines changed: 34 additions & 24 deletions

File tree

custom_components/victron_mqtt/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,14 +73,14 @@ async def handle_publish(call: ServiceCall) -> None:
7373
_LOGGER.info("Victron MQTT services registered")
7474

7575

76-
async def _update_listener(hass: HomeAssistant, entry: ConfigEntry):
76+
async def _update_listener(hass: HomeAssistant, entry: ConfigEntry) -> None:
7777
"""Handle options update."""
7878
_LOGGER.info("Options for victron_mqtt have been updated - applying changes")
7979
# Reload the integration to apply changes
8080
await hass.config_entries.async_reload(entry.entry_id)
8181

8282

83-
async def get_package_version(package_name) -> str:
83+
async def get_package_version(package_name: str) -> str:
8484
return await asyncio.get_event_loop().run_in_executor(
8585
None, importlib.metadata.version, package_name
8686
)
@@ -99,7 +99,7 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
9999
return True
100100

101101

102-
def _sync_library_logging():
102+
def _sync_library_logging() -> None:
103103
"""Sync the log level of the library to match integration logging."""
104104
lib_level = _LOGGER.getEffectiveLevel()
105105
_VICTRON_MQTT_LOGGER.setLevel(lib_level)

custom_components/victron_mqtt/config_flow.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -187,8 +187,8 @@ def __init__(self) -> None:
187187
self.hostname: str | None = None
188188
self.serial: str | None = None
189189
self.installation_id: str | None = None
190-
self.friendlyName: str | None = None
191-
self.modelName: str | None = None
190+
self.friendly_name: str | None = None
191+
self.model_name: str | None = None
192192

193193
async def async_step_user(
194194
self, user_input: dict[str, Any] | None = None
@@ -197,7 +197,7 @@ async def async_step_user(
197197
errors: dict[str, str] = {}
198198
if user_input is not None:
199199
_LOGGER.info("User input received: %s", user_input)
200-
data = {**user_input, CONF_SERIAL: self.serial, CONF_MODEL: self.modelName}
200+
data = {**user_input, CONF_SERIAL: self.serial, CONF_MODEL: self.model_name}
201201
data = {
202202
k: v for k, v in data.items() if v is not None
203203
} # remove None values.
@@ -220,7 +220,7 @@ async def async_step_user(
220220

221221
self._abort_if_unique_id_configured()
222222

223-
title = self.friendlyName or f"Victron OS {unique_id}"
223+
title = self.friendly_name or f"Victron OS {unique_id}"
224224
return self.async_create_entry(title=title, data=data)
225225

226226
if len(errors) > 0:
@@ -246,15 +246,15 @@ async def async_step_ssdp(
246246
self.hostname = str(urlparse(discovery_info.ssdp_location).hostname)
247247
self.serial = discovery_info.upnp["serialNumber"]
248248
self.installation_id = discovery_info.upnp["X_VrmPortalId"]
249-
self.modelName = discovery_info.upnp["modelName"]
250-
self.friendlyName = discovery_info.upnp["friendlyName"]
249+
self.model_name = discovery_info.upnp["model_name"]
250+
self.friendly_name = discovery_info.upnp["friendly_name"]
251251
_LOGGER.info(
252-
"SSDP: hostname=%s, serial=%s, installation_id=%s, modelName=%s, friendlyName=%s",
252+
"SSDP: hostname=%s, serial=%s, installation_id=%s, model_name=%s, friendly_name=%s",
253253
self.hostname,
254254
self.serial,
255255
self.installation_id,
256-
self.modelName,
257-
self.friendlyName,
256+
self.model_name,
257+
self.friendly_name,
258258
)
259259

260260
await self.async_set_unique_id(self.installation_id)
@@ -273,12 +273,12 @@ async def async_step_ssdp(
273273
return await self.async_step_user()
274274

275275
return self.async_create_entry(
276-
title=str(self.friendlyName),
276+
title=str(self.friendly_name),
277277
data={
278278
CONF_HOST: self.hostname,
279279
CONF_SERIAL: self.serial,
280280
CONF_INSTALLATION_ID: self.installation_id,
281-
CONF_MODEL: self.modelName,
281+
CONF_MODEL: self.model_name,
282282
},
283283
)
284284

custom_components/victron_mqtt/entity.py

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,11 @@
1616
from homeassistant.helpers.device_registry import DeviceInfo
1717
from homeassistant.helpers.entity import Entity
1818

19-
from .const import ENTITIES_DISABLE_BY_DEFAULT, ENTITIES_CATEGORY_DIAGNOSTIC, ENTITY_PREFIX
19+
from .const import (
20+
ENTITIES_CATEGORY_DIAGNOSTIC,
21+
ENTITIES_DISABLE_BY_DEFAULT,
22+
ENTITY_PREFIX,
23+
)
2024

2125
_LOGGER = logging.getLogger(__name__)
2226

@@ -29,7 +33,7 @@ def __init__(
2933
device: VictronVenusDevice,
3034
metric: VictronVenusMetric,
3135
device_info: DeviceInfo,
32-
type: str,
36+
entity_platform: str,
3337
simple_naming: bool,
3438
installation_id: str,
3539
) -> None:
@@ -38,9 +42,9 @@ def __init__(
3842
self._metric = metric
3943
self._device_info = device_info
4044
if simple_naming:
41-
entity_id = f"{type}.{ENTITY_PREFIX}_{metric.unique_id}"
45+
entity_id = f"{entity_platform}.{ENTITY_PREFIX}_{metric.unique_id}"
4246
else:
43-
entity_id = f"{type}.{ENTITY_PREFIX}_{installation_id}_{metric.unique_id}"
47+
entity_id = f"{entity_platform}.{ENTITY_PREFIX}_{installation_id}_{metric.unique_id}"
4448
self._attr_unique_id = entity_id
4549
self.entity_id = entity_id
4650
self._attr_native_unit_of_measurement = self._map_metric_to_unit_of_measurement(
@@ -56,8 +60,14 @@ def __init__(
5660
) # same as in merge_topics.py
5761
self._attr_translation_placeholders = metric.key_values
5862
# Specific changes related to HA
59-
self._attr_entity_category = EntityCategory.DIAGNOSTIC if metric.generic_short_id in ENTITIES_CATEGORY_DIAGNOSTIC else None
60-
self._attr_entity_registry_enabled_default = False if metric.generic_short_id in ENTITIES_DISABLE_BY_DEFAULT else True
63+
self._attr_entity_category = (
64+
EntityCategory.DIAGNOSTIC
65+
if metric.generic_short_id in ENTITIES_CATEGORY_DIAGNOSTIC
66+
else None
67+
)
68+
self._attr_entity_registry_enabled_default = (
69+
metric.generic_short_id not in ENTITIES_DISABLE_BY_DEFAULT
70+
)
6171

6272
_LOGGER.info("%s %s added. Based on: %s", type, self, repr(metric))
6373

custom_components/victron_mqtt/hub.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ def __init__(self, hass: HomeAssistant, entry: ConfigEntry) -> None:
113113

114114
self.hass.bus.async_listen_once(EVENT_HOMEASSISTANT_STOP, self.stop)
115115

116-
async def start(self):
116+
async def start(self) -> None:
117117
"""Start the Victron MQTT hub."""
118118
_LOGGER.info("Starting hub")
119119
try:
@@ -123,7 +123,7 @@ async def start(self):
123123
f"Cannot connect to the hub: {connect_error}"
124124
) from connect_error
125125

126-
async def stop(self, event: Event | None = None):
126+
async def stop(self, event: Event | None = None) -> None:
127127
"""Stop the Victron MQTT hub."""
128128
_LOGGER.info("Stopping hub")
129129
await self._hub.disconnect()
@@ -133,7 +133,7 @@ def _on_new_metric(
133133
hub: VictronVenusHub,
134134
device: VictronVenusDevice,
135135
metric: VictronVenusMetric,
136-
):
136+
) -> None:
137137
_LOGGER.info("New metric received. Device: %s, Metric: %s", device, metric)
138138
assert hub.installation_id is not None
139139
device_info = Hub._map_device_info(device, hub.installation_id)
@@ -163,7 +163,7 @@ def _map_device_info(
163163

164164
def register_add_entities_callback(
165165
self, async_add_entities: AddEntitiesCallback, kind: MetricKind
166-
):
166+
) -> None:
167167
"""Register a callback to add entities for a specific metric kind."""
168168
_LOGGER.info(
169169
"Registering AddEntitiesCallback. kind: %s, AddEntitiesCallback: %s",

0 commit comments

Comments
 (0)