Skip to content

Commit

Permalink
Fix missing names and name derivation (#339)
Browse files Browse the repository at this point in the history
  • Loading branch information
weltenwort authored Jan 7, 2024
1 parent a8d63a6 commit 1f774b2
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 21 deletions.
9 changes: 7 additions & 2 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,20 @@
"esbenp.prettier-vscode",
"ms-python.flake8",
"ms-python.black-formatter",
"tamasfe.even-better-toml"
"tamasfe.even-better-toml",
"thebutlah.reorder-python-imports"
],
"settings": {
"terminal.integrated.defaultProfile.linux": "zsh",
"python.venvPath": "/home/vscode/.cache/pypoetry/virtualenvs",
"editor.formatOnSave": true,
"editor.defaultFormatter": "esbenp.prettier-vscode",
"[python]": {
"editor.defaultFormatter": "ms-python.black-formatter"
"editor.defaultFormatter": "ms-python.black-formatter",
"editor.codeActionsOnSave": {
"source.organizeImports": false,
"source.organizeImports.reorder-python-imports": true
}
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions custom_components/rct_power/lib/entities.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,11 +219,13 @@ def get_matching_names(expression: str):
RctPowerSensorEntityDescription(
get_device_info=get_inverter_device_info,
key="db.core_temp",
name="Core Temperature",
state_class=SensorStateClass.MEASUREMENT,
),
RctPowerSensorEntityDescription(
get_device_info=get_inverter_device_info,
key="db.temp1",
name="Heat Sink Temperature",
state_class=SensorStateClass.MEASUREMENT,
),
RctPowerSensorEntityDescription(
Expand Down
50 changes: 31 additions & 19 deletions custom_components/rct_power/lib/entity.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,32 @@
from dataclasses import dataclass, field
from datetime import date, datetime
from dataclasses import dataclass
from dataclasses import field
from datetime import date
from datetime import datetime
from decimal import Decimal
from functools import cached_property
from typing import Any, Callable, List, Mapping, Optional

from homeassistant.components.sensor import SensorEntity, SensorEntityDescription
from typing import Any
from typing import Callable
from typing import List
from typing import Mapping
from typing import Optional

from homeassistant.components.sensor import SensorEntity
from homeassistant.components.sensor import SensorEntityDescription
from homeassistant.config_entries import ConfigEntry
from homeassistant.helpers.entity import DeviceInfo, EntityDescription
from homeassistant.helpers.typing import StateType, UndefinedType
from rctclient.registry import REGISTRY, ObjectInfo

from .api import (
ApiResponse,
ApiResponseValue,
ValidApiResponse,
get_valid_response_value_or,
)
from .const import ICON, EntityUpdatePriority
from homeassistant.helpers.entity import DeviceInfo
from homeassistant.helpers.entity import EntityDescription
from homeassistant.helpers.typing import StateType
from homeassistant.helpers.typing import UNDEFINED
from homeassistant.helpers.typing import UndefinedType
from rctclient.registry import ObjectInfo
from rctclient.registry import REGISTRY

from .api import ApiResponse
from .api import ApiResponseValue
from .api import get_valid_response_value_or
from .api import ValidApiResponse
from .const import EntityUpdatePriority
from .const import ICON
from .device_class_helpers import guess_device_class_from_unit
from .entry import RctPowerConfigEntryData
from .multi_coordinator_entity import MultiCoordinatorEntity
Expand Down Expand Up @@ -88,11 +98,13 @@ def unique_id(self) -> str | None:
object_ids = [str(object_info.object_id) for object_info in self.object_infos]
return "-".join([self.config_entry.entry_id, *object_ids])

@cached_property
@property
def name(self) -> str | UndefinedType | None:
"""Return the name of the entity."""
entity_name = self.entity_description.name or slugify_entity_name(
self.object_infos[0].name
entity_name = (
self.entity_description.name
if self.entity_description.name != UNDEFINED
else slugify_entity_name(self.object_infos[0].name)
)

return f"{self.config_entry_data.entity_prefix} {entity_name}"
Expand Down

0 comments on commit 1f774b2

Please sign in to comment.