Skip to content

Commit

Permalink
Add forbidden capabilities (#167)
Browse files Browse the repository at this point in the history
Forbidden capabilities are capabilities that cannot be present for a sensor to be added.
They are effectively the reverse of required capabilities, that must be present for a sensor to be added.
  • Loading branch information
WebSpider authored Nov 5, 2024
1 parent 02ad56e commit 1ec3cbb
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
8 changes: 8 additions & 0 deletions custom_components/myskoda/entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,19 @@ def device_info(self) -> DeviceInfo: # noqa: D102
def required_capabilities(self) -> list[CapabilityId]:
return []

def forbidden_capabilities(self) -> list[CapabilityId]:
return []

def is_supported(self) -> bool:
return all(
self.vehicle.has_capability(cap) for cap in self.required_capabilities()
)

def is_forbidden(self) -> bool:
return all(
self.vehicle.has_capability(cap) for cap in self.forbidden_capabilities()
)

def get_renders(self) -> dict[str, str]:
"""Return a dict of all vehicle image render URLs, keyed by view_point.
Expand Down
5 changes: 3 additions & 2 deletions custom_components/myskoda/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ def add_supported_entities(
for vin in coordinators:
for SensorClass in available_entities:
sensor = SensorClass(coordinators[vin], vin)
if sensor.is_supported():
entities.append(sensor)
if not sensor.is_forbidden():
if sensor.is_supported():
entities.append(sensor)

async_add_entities(entities, update_before_add=True)

0 comments on commit 1ec3cbb

Please sign in to comment.