Skip to content

Commit

Permalink
feat: try move unique ids into the sensors
Browse files Browse the repository at this point in the history
  • Loading branch information
wolffshots committed Apr 24, 2024
1 parent fedf190 commit c6c4473
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 8 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
| Entity | Type | Description |
| --------------- | ---------------- | ------------------------------------ |
| `connectivity` | `binary_sensor` | Show whether the server is connected |
| `open_sessions` | `sensor` | Show number of open audio sessions |
| `sessions` | `sensor` | Show number of open audio sessions |
| `libraries` | `sensor` | Number of libraries on the server |

## Installation
Expand Down
7 changes: 6 additions & 1 deletion custom_components/audiobookshelf/binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,15 @@ async def async_setup_entry(
class AudiobookshelfBinarySensor(AudiobookshelfEntity, BinarySensorEntity):
"""audiobookshelf binary_sensor class."""

@property
def unique_id(self) -> str:
"""Return a unique ID to use for this entity."""
return f"{DOMAIN}_connected"

@property
def name(self) -> str:
"""Return the name of the binary_sensor."""
return f"{DOMAIN}_connected"
return f"{DOMAIN} Connected"

@property
def device_class(self) -> str:
Expand Down
5 changes: 0 additions & 5 deletions custom_components/audiobookshelf/entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,6 @@ def __init__(
super().__init__(coordinator)
self.config_entry = config_entry

@property
def unique_id(self) -> str:
"""Return a unique ID to use for this entity."""
return self.config_entry.entry_id

@property
def device_info(self) -> dict[str, Any]:
return {
Expand Down
10 changes: 10 additions & 0 deletions custom_components/audiobookshelf/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ async def async_setup_entry(
class AudiobookshelfSessionsSensor(AudiobookshelfEntity):
"""audiobookshelf Sessions Sensor class."""

@property
def unique_id(self) -> str:
"""Return a unique ID to use for this entity."""
return f"{DOMAIN}_sessions"

@property
def name(self) -> str:
"""Return the name of the sensor."""
Expand Down Expand Up @@ -66,6 +71,11 @@ def device_class(self) -> str:
class AudiobookshelfNumberOfLibrariesSensor(AudiobookshelfEntity):
"""audiobookshelf Number of Libraries Sensor class."""

@property
def unique_id(self) -> str:
"""Return a unique ID to use for this entity."""
return f"{DOMAIN}_libraries"

@property
def name(self) -> str:
"""Return the name of the sensor."""
Expand Down
2 changes: 1 addition & 1 deletion info.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
| Entity | Type | Description |
| --------------- | ---------------- | ------------------------------------ |
| `connectivity` | `binary_sensor` | Show whether the server is connected |
| `open_sessions` | `sensor` | Show number of open audio sessions |
| `sessions` | `sensor` | Show number of open audio sessions |
| `libraries` | `sensor` | Number of libraries on the server |

{% if not installed %}
Expand Down

0 comments on commit c6c4473

Please sign in to comment.