Add entity translations to Kraken (#98765)

This commit is contained in:
Joost Lekkerkerker 2023-08-21 19:09:51 +02:00 committed by GitHub
parent 6023ee0cc4
commit 2d46b589b9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 71 additions and 18 deletions

View File

@ -47,93 +47,93 @@ class KrakenSensorEntityDescription(SensorEntityDescription, KrakenRequiredKeysM
SENSOR_TYPES: tuple[KrakenSensorEntityDescription, ...] = ( SENSOR_TYPES: tuple[KrakenSensorEntityDescription, ...] = (
KrakenSensorEntityDescription( KrakenSensorEntityDescription(
key="ask", key="ask",
name="Ask", translation_key="ask",
value_fn=lambda x, y: x.data[y]["ask"][0], value_fn=lambda x, y: x.data[y]["ask"][0],
), ),
KrakenSensorEntityDescription( KrakenSensorEntityDescription(
key="ask_volume", key="ask_volume",
name="Ask Volume", translation_key="ask_volume",
value_fn=lambda x, y: x.data[y]["ask"][1], value_fn=lambda x, y: x.data[y]["ask"][1],
entity_registry_enabled_default=False, entity_registry_enabled_default=False,
), ),
KrakenSensorEntityDescription( KrakenSensorEntityDescription(
key="bid", key="bid",
name="Bid", translation_key="bid",
value_fn=lambda x, y: x.data[y]["bid"][0], value_fn=lambda x, y: x.data[y]["bid"][0],
), ),
KrakenSensorEntityDescription( KrakenSensorEntityDescription(
key="bid_volume", key="bid_volume",
name="Bid Volume", translation_key="bid_volume",
value_fn=lambda x, y: x.data[y]["bid"][1], value_fn=lambda x, y: x.data[y]["bid"][1],
entity_registry_enabled_default=False, entity_registry_enabled_default=False,
), ),
KrakenSensorEntityDescription( KrakenSensorEntityDescription(
key="volume_today", key="volume_today",
name="Volume Today", translation_key="volume_today",
value_fn=lambda x, y: x.data[y]["volume"][0], value_fn=lambda x, y: x.data[y]["volume"][0],
entity_registry_enabled_default=False, entity_registry_enabled_default=False,
), ),
KrakenSensorEntityDescription( KrakenSensorEntityDescription(
key="volume_last_24h", key="volume_last_24h",
name="Volume last 24h", translation_key="volume_last_24h",
value_fn=lambda x, y: x.data[y]["volume"][1], value_fn=lambda x, y: x.data[y]["volume"][1],
entity_registry_enabled_default=False, entity_registry_enabled_default=False,
), ),
KrakenSensorEntityDescription( KrakenSensorEntityDescription(
key="volume_weighted_average_today", key="volume_weighted_average_today",
name="Volume weighted average today", translation_key="volume_weighted_average_today",
value_fn=lambda x, y: x.data[y]["volume_weighted_average"][0], value_fn=lambda x, y: x.data[y]["volume_weighted_average"][0],
entity_registry_enabled_default=False, entity_registry_enabled_default=False,
), ),
KrakenSensorEntityDescription( KrakenSensorEntityDescription(
key="volume_weighted_average_last_24h", key="volume_weighted_average_last_24h",
name="Volume weighted average last 24h", translation_key="volume_weighted_average_last_24h",
value_fn=lambda x, y: x.data[y]["volume_weighted_average"][1], value_fn=lambda x, y: x.data[y]["volume_weighted_average"][1],
entity_registry_enabled_default=False, entity_registry_enabled_default=False,
), ),
KrakenSensorEntityDescription( KrakenSensorEntityDescription(
key="number_of_trades_today", key="number_of_trades_today",
name="Number of trades today", translation_key="number_of_trades_today",
value_fn=lambda x, y: x.data[y]["number_of_trades"][0], value_fn=lambda x, y: x.data[y]["number_of_trades"][0],
entity_registry_enabled_default=False, entity_registry_enabled_default=False,
), ),
KrakenSensorEntityDescription( KrakenSensorEntityDescription(
key="number_of_trades_last_24h", key="number_of_trades_last_24h",
name="Number of trades last 24h", translation_key="number_of_trades_last_24h",
value_fn=lambda x, y: x.data[y]["number_of_trades"][1], value_fn=lambda x, y: x.data[y]["number_of_trades"][1],
entity_registry_enabled_default=False, entity_registry_enabled_default=False,
), ),
KrakenSensorEntityDescription( KrakenSensorEntityDescription(
key="last_trade_closed", key="last_trade_closed",
name="Last trade closed", translation_key="last_trade_closed",
value_fn=lambda x, y: x.data[y]["last_trade_closed"][0], value_fn=lambda x, y: x.data[y]["last_trade_closed"][0],
entity_registry_enabled_default=False, entity_registry_enabled_default=False,
), ),
KrakenSensorEntityDescription( KrakenSensorEntityDescription(
key="low_today", key="low_today",
name="Low today", translation_key="low_today",
value_fn=lambda x, y: x.data[y]["low"][0], value_fn=lambda x, y: x.data[y]["low"][0],
), ),
KrakenSensorEntityDescription( KrakenSensorEntityDescription(
key="low_last_24h", key="low_last_24h",
name="Low last 24h", translation_key="low_last_24h",
value_fn=lambda x, y: x.data[y]["low"][1], value_fn=lambda x, y: x.data[y]["low"][1],
entity_registry_enabled_default=False, entity_registry_enabled_default=False,
), ),
KrakenSensorEntityDescription( KrakenSensorEntityDescription(
key="high_today", key="high_today",
name="High today", translation_key="high_today",
value_fn=lambda x, y: x.data[y]["high"][0], value_fn=lambda x, y: x.data[y]["high"][0],
), ),
KrakenSensorEntityDescription( KrakenSensorEntityDescription(
key="high_last_24h", key="high_last_24h",
name="High last 24h", translation_key="high_last_24h",
value_fn=lambda x, y: x.data[y]["high"][1], value_fn=lambda x, y: x.data[y]["high"][1],
entity_registry_enabled_default=False, entity_registry_enabled_default=False,
), ),
KrakenSensorEntityDescription( KrakenSensorEntityDescription(
key="opening_price_today", key="opening_price_today",
name="Opening price today", translation_key="opening_price_today",
value_fn=lambda x, y: x.data[y]["opening_price"], value_fn=lambda x, y: x.data[y]["opening_price"],
entity_registry_enabled_default=False, entity_registry_enabled_default=False,
), ),
@ -207,6 +207,9 @@ class KrakenSensor(
entity_description: KrakenSensorEntityDescription entity_description: KrakenSensorEntityDescription
_attr_state_class = SensorStateClass.MEASUREMENT
_attr_has_entity_name = True
def __init__( def __init__(
self, self,
kraken_data: KrakenData, kraken_data: KrakenData,
@ -233,7 +236,6 @@ class KrakenSensor(
).lower() ).lower()
self._received_data_at_least_once = False self._received_data_at_least_once = False
self._available = True self._available = True
self._attr_state_class = SensorStateClass.MEASUREMENT
self._attr_device_info = DeviceInfo( self._attr_device_info = DeviceInfo(
configuration_url="https://www.kraken.com/", configuration_url="https://www.kraken.com/",
@ -242,7 +244,6 @@ class KrakenSensor(
manufacturer="Kraken.com", manufacturer="Kraken.com",
name=self._device_name, name=self._device_name,
) )
self._attr_has_entity_name = True
async def async_added_to_hass(self) -> None: async def async_added_to_hass(self) -> None:
"""Handle entity which will be added.""" """Handle entity which will be added."""

View File

@ -18,5 +18,57 @@
} }
} }
} }
},
"entity": {
"sensor": {
"ask": {
"name": "Ask"
},
"ask_volume": {
"name": "Ask volume"
},
"bid": {
"name": "Bid"
},
"bid_volume": {
"name": "Bid volume"
},
"volume_today": {
"name": "Volume today"
},
"volume_last_24h": {
"name": "Volume last 24h"
},
"volume_weighted_average_today": {
"name": "Volume weighted average today"
},
"volume_weighted_average_last_24h": {
"name": "Volume weighted average last 24h"
},
"number_of_trades_today": {
"name": "Number of trades today"
},
"number_of_trades_last_24h": {
"name": "Number of trades last 24h"
},
"last_trade_closed": {
"name": "Last trade closed"
},
"low_today": {
"name": "Low today"
},
"low_last_24h": {
"name": "Low last 24h"
},
"high_today": {
"name": "High today"
},
"high_last_24h": {
"name": "High last 24h"
},
"opening_price_today": {
"name": "Opening price today"
}
}
} }
} }