mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 11:17:21 +00:00
parent
ac8a12f99c
commit
b4669d8939
@ -50,77 +50,93 @@ class KrakenSensorEntityDescription(SensorEntityDescription, KrakenRequiredKeysM
|
|||||||
SENSOR_TYPES: tuple[KrakenSensorEntityDescription, ...] = (
|
SENSOR_TYPES: tuple[KrakenSensorEntityDescription, ...] = (
|
||||||
KrakenSensorEntityDescription(
|
KrakenSensorEntityDescription(
|
||||||
key="ask",
|
key="ask",
|
||||||
|
name="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",
|
||||||
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",
|
||||||
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",
|
||||||
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",
|
||||||
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",
|
||||||
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",
|
||||||
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",
|
||||||
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",
|
||||||
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",
|
||||||
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",
|
||||||
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",
|
||||||
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",
|
||||||
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",
|
||||||
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",
|
||||||
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",
|
||||||
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,
|
||||||
),
|
),
|
||||||
|
@ -109,19 +109,17 @@ class KrakenSensor(
|
|||||||
self.tracked_asset_pair_wsname = kraken_data.tradable_asset_pairs[
|
self.tracked_asset_pair_wsname = kraken_data.tradable_asset_pairs[
|
||||||
tracked_asset_pair
|
tracked_asset_pair
|
||||||
]
|
]
|
||||||
source_asset = tracked_asset_pair.split("/")[0]
|
|
||||||
self._target_asset = tracked_asset_pair.split("/")[1]
|
self._target_asset = tracked_asset_pair.split("/")[1]
|
||||||
if "number_of" not in description.key:
|
if "number_of" not in description.key:
|
||||||
self._attr_native_unit_of_measurement = self._target_asset
|
self._attr_native_unit_of_measurement = self._target_asset
|
||||||
self._device_name = f"{source_asset} {self._target_asset}"
|
self._device_name = create_device_name(tracked_asset_pair)
|
||||||
self._attr_name = "_".join(
|
self._attr_unique_id = "_".join(
|
||||||
[
|
[
|
||||||
tracked_asset_pair.split("/")[0],
|
tracked_asset_pair.split("/")[0],
|
||||||
tracked_asset_pair.split("/")[1],
|
tracked_asset_pair.split("/")[1],
|
||||||
description.key,
|
description.key,
|
||||||
]
|
]
|
||||||
)
|
).lower()
|
||||||
self._attr_unique_id = self._attr_name.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_state_class = SensorStateClass.MEASUREMENT
|
||||||
@ -129,10 +127,11 @@ class KrakenSensor(
|
|||||||
self._attr_device_info = DeviceInfo(
|
self._attr_device_info = DeviceInfo(
|
||||||
configuration_url="https://www.kraken.com/",
|
configuration_url="https://www.kraken.com/",
|
||||||
entry_type=device_registry.DeviceEntryType.SERVICE,
|
entry_type=device_registry.DeviceEntryType.SERVICE,
|
||||||
identifiers={(DOMAIN, f"{source_asset}_{self._target_asset}")},
|
identifiers={(DOMAIN, "_".join(self._device_name.split(" ")))},
|
||||||
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."""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user