parent
ac8a12f99c
commit
b4669d8939
2 changed files with 21 additions and 6 deletions
|
@ -50,77 +50,93 @@ class KrakenSensorEntityDescription(SensorEntityDescription, KrakenRequiredKeysM
|
|||
SENSOR_TYPES: tuple[KrakenSensorEntityDescription, ...] = (
|
||||
KrakenSensorEntityDescription(
|
||||
key="ask",
|
||||
name="Ask",
|
||||
value_fn=lambda x, y: x.data[y]["ask"][0],
|
||||
),
|
||||
KrakenSensorEntityDescription(
|
||||
key="ask_volume",
|
||||
name="Ask Volume",
|
||||
value_fn=lambda x, y: x.data[y]["ask"][1],
|
||||
entity_registry_enabled_default=False,
|
||||
),
|
||||
KrakenSensorEntityDescription(
|
||||
key="bid",
|
||||
name="Bid",
|
||||
value_fn=lambda x, y: x.data[y]["bid"][0],
|
||||
),
|
||||
KrakenSensorEntityDescription(
|
||||
key="bid_volume",
|
||||
name="Bid Volume",
|
||||
value_fn=lambda x, y: x.data[y]["bid"][1],
|
||||
entity_registry_enabled_default=False,
|
||||
),
|
||||
KrakenSensorEntityDescription(
|
||||
key="volume_today",
|
||||
name="Volume Today",
|
||||
value_fn=lambda x, y: x.data[y]["volume"][0],
|
||||
entity_registry_enabled_default=False,
|
||||
),
|
||||
KrakenSensorEntityDescription(
|
||||
key="volume_last_24h",
|
||||
name="Volume last 24h",
|
||||
value_fn=lambda x, y: x.data[y]["volume"][1],
|
||||
entity_registry_enabled_default=False,
|
||||
),
|
||||
KrakenSensorEntityDescription(
|
||||
key="volume_weighted_average_today",
|
||||
name="Volume weighted average today",
|
||||
value_fn=lambda x, y: x.data[y]["volume_weighted_average"][0],
|
||||
entity_registry_enabled_default=False,
|
||||
),
|
||||
KrakenSensorEntityDescription(
|
||||
key="volume_weighted_average_last_24h",
|
||||
name="Volume weighted average last 24h",
|
||||
value_fn=lambda x, y: x.data[y]["volume_weighted_average"][1],
|
||||
entity_registry_enabled_default=False,
|
||||
),
|
||||
KrakenSensorEntityDescription(
|
||||
key="number_of_trades_today",
|
||||
name="Number of trades today",
|
||||
value_fn=lambda x, y: x.data[y]["number_of_trades"][0],
|
||||
entity_registry_enabled_default=False,
|
||||
),
|
||||
KrakenSensorEntityDescription(
|
||||
key="number_of_trades_last_24h",
|
||||
name="Number of trades last 24h",
|
||||
value_fn=lambda x, y: x.data[y]["number_of_trades"][1],
|
||||
entity_registry_enabled_default=False,
|
||||
),
|
||||
KrakenSensorEntityDescription(
|
||||
key="last_trade_closed",
|
||||
name="Last trade closed",
|
||||
value_fn=lambda x, y: x.data[y]["last_trade_closed"][0],
|
||||
entity_registry_enabled_default=False,
|
||||
),
|
||||
KrakenSensorEntityDescription(
|
||||
key="low_today",
|
||||
name="Low today",
|
||||
value_fn=lambda x, y: x.data[y]["low"][0],
|
||||
),
|
||||
KrakenSensorEntityDescription(
|
||||
key="low_last_24h",
|
||||
name="Low last 24h",
|
||||
value_fn=lambda x, y: x.data[y]["low"][1],
|
||||
entity_registry_enabled_default=False,
|
||||
),
|
||||
KrakenSensorEntityDescription(
|
||||
key="high_today",
|
||||
name="High today",
|
||||
value_fn=lambda x, y: x.data[y]["high"][0],
|
||||
),
|
||||
KrakenSensorEntityDescription(
|
||||
key="high_last_24h",
|
||||
name="High last 24h",
|
||||
value_fn=lambda x, y: x.data[y]["high"][1],
|
||||
entity_registry_enabled_default=False,
|
||||
),
|
||||
KrakenSensorEntityDescription(
|
||||
key="opening_price_today",
|
||||
name="Opening price today",
|
||||
value_fn=lambda x, y: x.data[y]["opening_price"],
|
||||
entity_registry_enabled_default=False,
|
||||
),
|
||||
|
|
|
@ -109,19 +109,17 @@ class KrakenSensor(
|
|||
self.tracked_asset_pair_wsname = kraken_data.tradable_asset_pairs[
|
||||
tracked_asset_pair
|
||||
]
|
||||
source_asset = tracked_asset_pair.split("/")[0]
|
||||
self._target_asset = tracked_asset_pair.split("/")[1]
|
||||
if "number_of" not in description.key:
|
||||
self._attr_native_unit_of_measurement = self._target_asset
|
||||
self._device_name = f"{source_asset} {self._target_asset}"
|
||||
self._attr_name = "_".join(
|
||||
self._device_name = create_device_name(tracked_asset_pair)
|
||||
self._attr_unique_id = "_".join(
|
||||
[
|
||||
tracked_asset_pair.split("/")[0],
|
||||
tracked_asset_pair.split("/")[1],
|
||||
description.key,
|
||||
]
|
||||
)
|
||||
self._attr_unique_id = self._attr_name.lower()
|
||||
).lower()
|
||||
self._received_data_at_least_once = False
|
||||
self._available = True
|
||||
self._attr_state_class = SensorStateClass.MEASUREMENT
|
||||
|
@ -129,10 +127,11 @@ class KrakenSensor(
|
|||
self._attr_device_info = DeviceInfo(
|
||||
configuration_url="https://www.kraken.com/",
|
||||
entry_type=device_registry.DeviceEntryType.SERVICE,
|
||||
identifiers={(DOMAIN, f"{source_asset}_{self._target_asset}")},
|
||||
identifiers={(DOMAIN, "_".join(self._device_name.split(" ")))},
|
||||
manufacturer="Kraken.com",
|
||||
name=self._device_name,
|
||||
)
|
||||
self._attr_has_entity_name = True
|
||||
|
||||
async def async_added_to_hass(self) -> None:
|
||||
"""Handle entity which will be added."""
|
||||
|
|
Loading…
Add table
Reference in a new issue