Skip to content

Commit

Permalink
Merge pull request #544 from stickpin/Add_EntityCategory
Browse files Browse the repository at this point in the history
Reorganize entities by categories
  • Loading branch information
robinostlund authored Jan 17, 2024
2 parents ff62871 + 4efaee4 commit 7daa4fe
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
9 changes: 9 additions & 0 deletions custom_components/volkswagencarnet/binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from homeassistant.components.binary_sensor import DEVICE_CLASSES, BinarySensorEntity, BinarySensorDeviceClass
from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity import EntityCategory

from . import VolkswagenEntity
from .const import DATA_KEY, DATA, DOMAIN, UPDATE_CALLBACK
Expand Down Expand Up @@ -54,3 +55,11 @@ def device_class(self) -> Union[BinarySensorDeviceClass, str, None]:
return self.instrument.device_class
_LOGGER.warning(f"Unknown device class {self.instrument.device_class}")
return None

@property
def entity_category(self) -> Union[EntityCategory, str, None]:
"""Return entity category."""
if self.instrument.entity_type == "diag":
return EntityCategory.DIAGNOSTIC
if self.instrument.entity_type == "config":
return EntityCategory.CONFIG
9 changes: 9 additions & 0 deletions custom_components/volkswagencarnet/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
)
from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity import EntityCategory

from . import VolkswagenEntity
from .const import DATA_KEY, DATA, DOMAIN, UPDATE_CALLBACK
Expand Down Expand Up @@ -79,3 +80,11 @@ def state_class(self) -> Union[SensorStateClass, None]:
return self.instrument.state_class
_LOGGER.warning(f"Unknown state class {self.instrument.state_class}")
return None

@property
def entity_category(self) -> Union[EntityCategory, str, None]:
"""Return entity category."""
if self.instrument.entity_type == "diag":
return EntityCategory.DIAGNOSTIC
if self.instrument.entity_type == "config":
return EntityCategory.CONFIG
8 changes: 8 additions & 0 deletions custom_components/volkswagencarnet/switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,14 @@ async def async_turn_off(self, **kwargs):
await self.instrument.turn_off()
self.notify_updated()

@property
def entity_category(self) -> Union[EntityCategory, str, None]:
"""Return entity category."""
if self.instrument.entity_type == "diag":
return EntityCategory.DIAGNOSTIC
if self.instrument.entity_type == "config":
return EntityCategory.CONFIG

@property
def assumed_state(self):
"""Return state assumption."""
Expand Down

0 comments on commit 7daa4fe

Please sign in to comment.