Skip to content

Tibber available #13865

Merged
pvizeli merged 4 commits intodevfrom
tibber_avail
Apr 20, 2018
Merged

Tibber available #13865
pvizeli merged 4 commits intodevfrom
tibber_avail

Conversation

@Danielhiversen
Copy link
Copy Markdown
Member

Description:

Set the availability status of the Tibber sensor.
Fetching the data in a smarter way.

Checklist:

  • The code change is tested and works locally.
  • Local tests pass with tox. Your PR cannot be merged unless tests pass

Copy link
Copy Markdown
Member

@pvizeli pvizeli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good 👍

return

@Throttle(MIN_TIME_BETWEEN_UPDATES)
async def _fetch_data():
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Expose this as normal member variable, So It don't create a function every 1min that maybe not used and need cleanup from garbridge collector.

self._device_state_attributes['estimated_annual_consumption'] = \
data['meteringPointData']['estimatedAnnualConsumption']

def _find_current_price():
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you export the other, you can also export this

(self._newest_data_timestamp - now).total_seconds()/3600 < 12
or not self._is_available):
_LOGGER.debug("Asking for new data.")
await _fetch_data()
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Optional, since you us Throttle, you could call this every time.

self._device_state_attributes['estimated_annual_consumption'] =\
data['meteringPointData']['estimatedAnnualConsumption']
_find_current_price()
self._is_available = _find_current_price()
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_find_currect_price() should now return True/false

for key, price_total in self._tibber_home.price_total.items():
price_time = dt_util.as_utc(dt_util.parse_datetime(key))
price_total = round(price_total, 3)
time_diff = (now - price_time).total_seconds()/60
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

undefined name 'now'

@home-assistant home-assistant deleted a comment from houndci-bot Apr 14, 2018
@Danielhiversen
Copy link
Copy Markdown
Member Author

@pvizeli thanks for your comments. Always good review from you 👍

@Danielhiversen
Copy link
Copy Markdown
Member Author

@pvizeli Is this good now?

@pvizeli pvizeli merged commit 825f94f into dev Apr 20, 2018
@Danielhiversen Danielhiversen deleted the tibber_avail branch April 20, 2018 10:02
@balloob balloob mentioned this pull request Apr 27, 2018
@home-assistant home-assistant locked and limited conversation to collaborators Jul 26, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants