diff --git a/README.md b/README.md index 9e8c271..eac916d 100644 --- a/README.md +++ b/README.md @@ -26,6 +26,7 @@ Configure the sensor(s) in ``configuration.yaml``. sensor: - platform: binance decimals: 8 + update_interval: 60 symbols: - BTCUSDT - ETHUSDT diff --git a/custom_components/binance/binance_ticker_sensor.py b/custom_components/binance/binance_ticker_sensor.py index a3cd6bc..41d81b4 100644 --- a/custom_components/binance/binance_ticker_sensor.py +++ b/custom_components/binance/binance_ticker_sensor.py @@ -17,11 +17,12 @@ class BinanceTickerSensor(Entity): - def __init__(self, symbol, decimals): + def __init__(self, symbol, decimals, updateInterval): self._attr_device_class = SensorDeviceClass.MONETARY self._name = "Binance Ticker "+symbol.upper() self._symbol = symbol self._decimals = decimals + self._updateInterval = updateInterval self._state = STATE_UNKNOWN self._data = {} @@ -37,6 +38,10 @@ def symbol(self): def decimals(self): return self._decimals + @property + def updateInterval(self): + return self._updateInterval + @property def state(self): return self._state @@ -47,7 +52,7 @@ def extra_state_attributes(self): async def async_added_to_hass(self): self.hass.helpers.event.async_track_time_interval( - self.update, timedelta(seconds=60) + self.update, timedelta(seconds=updateInterval) ) def update(self, *args): diff --git a/custom_components/binance/const.py b/custom_components/binance/const.py index 2dc938d..9079055 100644 --- a/custom_components/binance/const.py +++ b/custom_components/binance/const.py @@ -2,3 +2,4 @@ CONF_SYMBOLS = "symbols" CONF_DECIMALS = "decimals" +CONF_UPDATE_INVERVAL = "update_interval" diff --git a/custom_components/binance/manifest.json b/custom_components/binance/manifest.json index 156d2e8..e59a8cc 100644 --- a/custom_components/binance/manifest.json +++ b/custom_components/binance/manifest.json @@ -8,5 +8,5 @@ "integration_type": "hub", "iot_class": "cloud_polling", "issue_tracker": "https://github.com/Kartax/home-assistant-binance/issues", - "version": "1.1.4" + "version": "1.2.0" } diff --git a/custom_components/binance/sensor.py b/custom_components/binance/sensor.py index 5da4298..07df89a 100644 --- a/custom_components/binance/sensor.py +++ b/custom_components/binance/sensor.py @@ -6,7 +6,8 @@ from homeassistant.components.sensor import PLATFORM_SCHEMA from .const import ( CONF_SYMBOLS, - CONF_DECIMALS + CONF_DECIMALS, + CONF_UPDATE_INVERVAL ) from .binance_ticker_sensor import BinanceTickerSensor @@ -17,14 +18,16 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend( { vol.Required(CONF_SYMBOLS): vol.All(cv.ensure_list, [cv.string]), - vol.Optional(CONF_DECIMALS, default=8): cv.positive_int + vol.Optional(CONF_DECIMALS, default=8): cv.positive_int, + vol.Optional(CONF_UPDATE_INVERVAL, default=60): cv.positive_int } ) def setup_platform(hass, config, add_entities, discovery_info=None): symbols = config.get(CONF_SYMBOLS) decimals = config.get(CONF_DECIMALS) + updateInterval = config.get(CONF_UPDATE_INVERVAL) for symbol in symbols: - logger.debug("Setup BinanceTickerSensor %s %s", symbol, decimals) - add_entities([BinanceTickerSensor(symbol, decimals)], True) + logger.debug("Setup BinanceTickerSensor %s %s %s", symbol, decimals, updateInterval) + add_entities([BinanceTickerSensor(symbol, decimals, updateInterval)], True)