Migrate Transmission to new entity naming (#95436)

This commit is contained in:
avee87 2023-06-28 13:00:06 +01:00 committed by GitHub
parent 103375ef95
commit 6c2c4c989f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 10 deletions

View file

@ -1,7 +1,7 @@
"""Constants for the Transmission Bittorent Client component.""" """Constants for the Transmission Bittorent Client component."""
DOMAIN = "transmission" DOMAIN = "transmission"
SWITCH_TYPES = {"on_off": "Switch", "turtle_mode": "Turtle Mode"} SWITCH_TYPES = {"on_off": "Switch", "turtle_mode": "Turtle mode"}
ORDER_NEWEST_FIRST = "newest_first" ORDER_NEWEST_FIRST = "newest_first"
ORDER_OLDEST_FIRST = "oldest_first" ORDER_OLDEST_FIRST = "oldest_first"

View file

@ -38,21 +38,21 @@ async def async_setup_entry(
name = config_entry.data[CONF_NAME] name = config_entry.data[CONF_NAME]
dev = [ dev = [
TransmissionSpeedSensor(tm_client, name, "Down Speed", "download"), TransmissionSpeedSensor(tm_client, name, "Down speed", "download"),
TransmissionSpeedSensor(tm_client, name, "Up Speed", "upload"), TransmissionSpeedSensor(tm_client, name, "Up speed", "upload"),
TransmissionStatusSensor(tm_client, name, "Status", "status"), TransmissionStatusSensor(tm_client, name, "Status", "status"),
TransmissionTorrentsSensor( TransmissionTorrentsSensor(
tm_client, name, "Active Torrents", "active_torrents" tm_client, name, "Active torrents", "active_torrents"
), ),
TransmissionTorrentsSensor( TransmissionTorrentsSensor(
tm_client, name, "Paused Torrents", "paused_torrents" tm_client, name, "Paused torrents", "paused_torrents"
), ),
TransmissionTorrentsSensor(tm_client, name, "Total Torrents", "total_torrents"), TransmissionTorrentsSensor(tm_client, name, "Total torrents", "total_torrents"),
TransmissionTorrentsSensor( TransmissionTorrentsSensor(
tm_client, name, "Completed Torrents", "completed_torrents" tm_client, name, "Completed torrents", "completed_torrents"
), ),
TransmissionTorrentsSensor( TransmissionTorrentsSensor(
tm_client, name, "Started Torrents", "started_torrents" tm_client, name, "Started torrents", "started_torrents"
), ),
] ]
@ -62,12 +62,13 @@ async def async_setup_entry(
class TransmissionSensor(SensorEntity): class TransmissionSensor(SensorEntity):
"""A base class for all Transmission sensors.""" """A base class for all Transmission sensors."""
_attr_has_entity_name = True
_attr_should_poll = False _attr_should_poll = False
def __init__(self, tm_client, client_name, sensor_name, key): def __init__(self, tm_client, client_name, sensor_name, key):
"""Initialize the sensor.""" """Initialize the sensor."""
self._tm_client: TransmissionClient = tm_client self._tm_client: TransmissionClient = tm_client
self._attr_name = f"{client_name} {sensor_name}" self._attr_name = sensor_name
self._key = key self._key = key
self._state = None self._state = None
self._attr_unique_id = f"{tm_client.config_entry.entry_id}-{key}" self._attr_unique_id = f"{tm_client.config_entry.entry_id}-{key}"

View file

@ -36,11 +36,12 @@ async def async_setup_entry(
class TransmissionSwitch(SwitchEntity): class TransmissionSwitch(SwitchEntity):
"""Representation of a Transmission switch.""" """Representation of a Transmission switch."""
_attr_has_entity_name = True
_attr_should_poll = False _attr_should_poll = False
def __init__(self, switch_type, switch_name, tm_client, client_name): def __init__(self, switch_type, switch_name, tm_client, client_name):
"""Initialize the Transmission switch.""" """Initialize the Transmission switch."""
self._attr_name = f"{client_name} {switch_name}" self._attr_name = switch_name
self.type = switch_type self.type = switch_type
self._tm_client = tm_client self._tm_client = tm_client
self._state = STATE_OFF self._state = STATE_OFF