1
mirror of https://github.com/home-assistant/core synced 2024-10-01 05:30:36 +02:00

Use entity class attributes for Blockchain (#52894)

* Use entity class attributes for blockchain

* rework

* tweak
This commit is contained in:
Robert Hillis 2021-07-12 16:49:38 -04:00 committed by GitHub
parent adb5fd5a03
commit 7ef4bd53ec
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -46,39 +46,15 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
class BlockchainSensor(SensorEntity):
"""Representation of a Blockchain.com sensor."""
_attr_extra_state_attributes = {ATTR_ATTRIBUTION: ATTRIBUTION}
_attr_icon = ICON
_attr_unit_of_measurement = "BTC"
def __init__(self, name, addresses):
"""Initialize the sensor."""
self._name = name
self._attr_name = name
self.addresses = addresses
self._state = None
self._unit_of_measurement = "BTC"
@property
def name(self):
"""Return the name of the sensor."""
return self._name
@property
def state(self):
"""Return the state of the sensor."""
return self._state
@property
def unit_of_measurement(self):
"""Return the unit of measurement this sensor expresses itself in."""
return self._unit_of_measurement
@property
def icon(self):
"""Return the icon to use in the frontend, if any."""
return ICON
@property
def extra_state_attributes(self):
"""Return the state attributes of the sensor."""
return {ATTR_ATTRIBUTION: ATTRIBUTION}
def update(self):
"""Get the latest state of the sensor."""
self._state = get_balance(self.addresses)
self._attr_state = get_balance(self.addresses)