mirror of
https://github.com/home-assistant/core.git
synced 2025-12-24 21:06:19 +00:00
Black
This commit is contained in:
@@ -8,12 +8,12 @@ from . import CONF_WALLETS, IotaDevice
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
ATTR_TESTNET = 'testnet'
|
||||
ATTR_URL = 'url'
|
||||
ATTR_TESTNET = "testnet"
|
||||
ATTR_URL = "url"
|
||||
|
||||
CONF_IRI = 'iri'
|
||||
CONF_SEED = 'seed'
|
||||
CONF_TESTNET = 'testnet'
|
||||
CONF_IRI = "iri"
|
||||
CONF_SEED = "seed"
|
||||
CONF_TESTNET = "testnet"
|
||||
|
||||
SCAN_INTERVAL = timedelta(minutes=3)
|
||||
|
||||
@@ -21,8 +21,9 @@ SCAN_INTERVAL = timedelta(minutes=3)
|
||||
def setup_platform(hass, config, add_entities, discovery_info=None):
|
||||
"""Set up the IOTA sensor."""
|
||||
iota_config = discovery_info
|
||||
sensors = [IotaBalanceSensor(wallet, iota_config)
|
||||
for wallet in iota_config[CONF_WALLETS]]
|
||||
sensors = [
|
||||
IotaBalanceSensor(wallet, iota_config) for wallet in iota_config[CONF_WALLETS]
|
||||
]
|
||||
|
||||
sensors.append(IotaNodeSensor(iota_config=iota_config))
|
||||
|
||||
@@ -35,14 +36,17 @@ class IotaBalanceSensor(IotaDevice):
|
||||
def __init__(self, wallet_config, iota_config):
|
||||
"""Initialize the sensor."""
|
||||
super().__init__(
|
||||
name=wallet_config[CONF_NAME], seed=wallet_config[CONF_SEED],
|
||||
iri=iota_config[CONF_IRI], is_testnet=iota_config[CONF_TESTNET])
|
||||
name=wallet_config[CONF_NAME],
|
||||
seed=wallet_config[CONF_SEED],
|
||||
iri=iota_config[CONF_IRI],
|
||||
is_testnet=iota_config[CONF_TESTNET],
|
||||
)
|
||||
self._state = None
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
"""Return the name of the sensor."""
|
||||
return '{} Balance'.format(self._name)
|
||||
return "{} Balance".format(self._name)
|
||||
|
||||
@property
|
||||
def state(self):
|
||||
@@ -52,11 +56,11 @@ class IotaBalanceSensor(IotaDevice):
|
||||
@property
|
||||
def unit_of_measurement(self):
|
||||
"""Return the unit of measurement."""
|
||||
return 'IOTA'
|
||||
return "IOTA"
|
||||
|
||||
def update(self):
|
||||
"""Fetch new balance from IRI."""
|
||||
self._state = self.api.get_inputs()['totalBalance']
|
||||
self._state = self.api.get_inputs()["totalBalance"]
|
||||
|
||||
|
||||
class IotaNodeSensor(IotaDevice):
|
||||
@@ -65,15 +69,18 @@ class IotaNodeSensor(IotaDevice):
|
||||
def __init__(self, iota_config):
|
||||
"""Initialize the sensor."""
|
||||
super().__init__(
|
||||
name='Node Info', seed=None, iri=iota_config[CONF_IRI],
|
||||
is_testnet=iota_config[CONF_TESTNET])
|
||||
name="Node Info",
|
||||
seed=None,
|
||||
iri=iota_config[CONF_IRI],
|
||||
is_testnet=iota_config[CONF_TESTNET],
|
||||
)
|
||||
self._state = None
|
||||
self._attr = {ATTR_URL: self.iri, ATTR_TESTNET: self.is_testnet}
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
"""Return the name of the sensor."""
|
||||
return 'IOTA Node'
|
||||
return "IOTA Node"
|
||||
|
||||
@property
|
||||
def state(self):
|
||||
@@ -88,7 +95,7 @@ class IotaNodeSensor(IotaDevice):
|
||||
def update(self):
|
||||
"""Fetch new attributes IRI node."""
|
||||
node_info = self.api.get_node_info()
|
||||
self._state = node_info.get('appVersion')
|
||||
self._state = node_info.get("appVersion")
|
||||
|
||||
# convert values to raw string formats
|
||||
self._attr.update({k: str(v) for k, v in node_info.items()})
|
||||
|
||||
Reference in New Issue
Block a user