Skip to content

Commit

Permalink
Release 0.2.7
Browse files Browse the repository at this point in the history
# Release 0.2.7

## Added
Add support for [winddelen.nl](https://winddelen.nl)

## Updated
- Boto3 1.26.70 -> 1.26.147
- pycognito2022.12.0 -> 2023.5.0

## Removed
- nothing
  • Loading branch information
jobvk authored Jun 6, 2023
1 parent 6883ab5 commit 74b53f8
Show file tree
Hide file tree
Showing 11 changed files with 59 additions and 27 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
[![](https://img.shields.io/badge/PayPal-00457C?style=flat&logo=paypal&logoColor=white)](https://paypal.me/jobvankoeveringe)
[![Buy me a coffee](https://img.shields.io/badge/-buy_me_a%C2%A0coffee-gray?logo=buy-me-a-coffee&color=orange)](https://www.buymeacoffee.com/jobvk)

Home Assistant component for the Windcentrale
Home Assistant component for the Windcentrale & Winddelen

The `Windcentrale` component is a Home Assistant component which lets you get sensor and news data from all wind turbines.

The official website https://www.windcentrale.nl
The official websites are https://www.windcentrale.nl and https://winddelen.nl

## Table of Contents

Expand Down Expand Up @@ -63,7 +63,7 @@ The Windcentrale component can be configured by config flow.
Go to Settings and then Devices & Services, select Integrations and click on the `+ add integration`, select Windcentrale and configure the setup on the form.
Fill in your email address and password that you use for signing in to the website, and press submit.

![image](https://user-images.githubusercontent.com/32730202/194356727-0d3c03f3-28b8-4a87-a940-7f42ebb69bea.png)
![image](https://github.com/jobvk/Home-Assistant-Windcentrale/assets/32730202/30b7a02e-b5c5-45bf-8a16-ec325a441ed5)

### Options

Expand Down
5 changes: 3 additions & 2 deletions custom_components/windcentrale/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import json
import voluptuous as vol
from homeassistant import config_entries, core, exceptions
from homeassistant.const import CONF_EMAIL, CONF_PASSWORD, CONF_SHOW_ON_MAP
from homeassistant.const import CONF_EMAIL, CONF_PASSWORD, CONF_PLATFORM, CONF_SHOW_ON_MAP
from homeassistant.core import callback
from .const import *
from .wind import Credentials
Expand All @@ -13,6 +13,7 @@
WINDTURBINE_SCHEMA = vol.Schema({
vol.Required(CONF_EMAIL): str,
vol.Required(CONF_PASSWORD): str,
vol.Required(CONF_PLATFORM, default=PLATFORM_SELECT[0]): vol.In(PLATFORM_SELECT),
})

class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
Expand Down Expand Up @@ -69,7 +70,7 @@ async def async_step_init(self, user_input=None):

async def validate_input(hass, user_input: dict):
"""Validate the user input"""
credentails = Credentials(hass, user_input[CONF_EMAIL], user_input[CONF_PASSWORD])
credentails = Credentials(hass, user_input[CONF_EMAIL], user_input[CONF_PASSWORD], user_input[CONF_PLATFORM])
result_user_credentails = await credentails.authenticate_user_credentails()
user_input[CONF_TOKEN_HEADER] = json.dumps(result_user_credentails)
if result_user_credentails == "invalid_parameter":
Expand Down
9 changes: 9 additions & 0 deletions custom_components/windcentrale/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,17 @@
NEWS_INTERVAL = 5 #min
TOKEN_INTERVAL = 55 #min

PLATFORM_SELECT = ["Windcentrale", "Winddelen"]
DEFAULT_SHOW_ON_MAP = False

WINDCENTRALE_BASE_URL = "mijn.windcentrale.nl"
WINDCENTRALE_POOL_ID = "eu-west-1_U7eYBPrBd"
WINDCENTRALE_CLIENT_ID = "715j3r0trk7o8dqg3md57il7q0"

WINDDELEN_BASE_URL = "mijn.winddelen.nl"
WINDDELEN_POOL_ID = "eu-west-1_3ujjjPxxH"
WINDDELEN_CLIENT_ID = "11edho7vncqa74o1bju4tlgnt0"

# Format:
# Name: [Manufacturer, Model, Location, Latitude, Longitude, Total Shares, Start Date, Energy Prognoses (kWh)]
WINDTURBINES_LIST = {
Expand Down
6 changes: 3 additions & 3 deletions custom_components/windcentrale/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@
"iot_class": "cloud_polling",
"issue_tracker": "https://github.com/jobvk/Home-Assistant-Windcentrale/issues",
"loggers": ["boto3"],
"requirements": ["boto3==1.26.70", "pycognito==2022.12.0"],
"version": "0.2.6"
}
"requirements": ["boto3==1.26.147", "pycognito==2023.5.0"],
"version": "0.2.7"
}
3 changes: 2 additions & 1 deletion custom_components/windcentrale/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
"description": "If you need help with the configuration have a look over here: https://github.com/jobvk/Home-Assistant-Windcentrale",
"data": {
"email": "Enter your email address",
"password": "Enter your password"
"password": "Enter your password",
"platform": "Select your website"
}
}
},
Expand Down
3 changes: 2 additions & 1 deletion custom_components/windcentrale/translations/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
"description": "Wenn man Hilfe braucht bei der Konfiguration, schau dann mal hier: https://github.com/jobvk/Home-Assistant-Windcentrale",
"data": {
"email": "Geben Sie Ihre E-Mailadresse ein",
"password": "Geben Sie Ihr Passwort ein"
"password": "Geben Sie Ihr Passwort ein",
"platform": "Wählen Sie Ihre Website aus"
}
}
},
Expand Down
3 changes: 2 additions & 1 deletion custom_components/windcentrale/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
"description": "If you need help with the configuration have a look over here: https://github.com/jobvk/Home-Assistant-Windcentrale",
"data": {
"email": "Enter your email address",
"password": "Enter your password"
"password": "Enter your password",
"platform": "Select your website"
}
}
},
Expand Down
3 changes: 2 additions & 1 deletion custom_components/windcentrale/translations/nl.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
"description": "Als je hulp nodig hebt bij de configuratie, kijk dan hier: https://github.com/jobvk/Home-Assistant-Windcentrale",
"data": {
"email": "Vul je e-mailadres in",
"password": "Vul je wachtwoord in"
"password": "Vul je wachtwoord in",
"platform": "Selecteer je website"
}
}
},
Expand Down
40 changes: 29 additions & 11 deletions custom_components/windcentrale/wind.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from defusedxml import ElementTree
from homeassistant.helpers.event import async_track_point_in_utc_time
from homeassistant.util import dt as dt_util
from homeassistant.const import CONF_EMAIL, CONF_PASSWORD, CONF_SHOW_ON_MAP
from homeassistant.const import CONF_EMAIL, CONF_PASSWORD, CONF_PLATFORM, CONF_SHOW_ON_MAP
from .const import *

_LOGGER = logging.getLogger(__name__)
Expand All @@ -22,7 +22,9 @@ def __init__(self, hass, config_entry):
self.id = DOMAIN
self.tokens = None
self.show_on_map = self.config_entry.options.get(CONF_SHOW_ON_MAP, DEFAULT_SHOW_ON_MAP)
self.credentialsapi = Credentials(self.hass, self.config_entry.data[CONF_EMAIL], self.config_entry.data[CONF_PASSWORD])
self.platform = self.config_entry.data.get(CONF_PLATFORM, "Windcentrale")
self.base_url = self.get_base_url()
self.credentialsapi = Credentials(self.hass, self.config_entry.data[CONF_EMAIL], self.config_entry.data[CONF_PASSWORD], self.platform)

self.windturbines = []
for windturbine in WINDTURBINES_LIST:
Expand Down Expand Up @@ -60,6 +62,12 @@ async def async_update_token(self, *_):
async def update_token_now(self):
self.tokens = await self.credentialsapi.authenticate_user_credentails()

def get_base_url(self):
if self.platform == "Windcentrale":
return WINDCENTRALE_BASE_URL
elif self.platform == "Winddelen":
return WINDDELEN_BASE_URL

class Windturbine:
"Create windturbine and collect data"
def __init__(self, wind, hass, windturbine_name, windturbine_code, windturbine_shares):
Expand Down Expand Up @@ -157,11 +165,10 @@ def __init__(self, hass, wind, windturbineId, windturbineName):
self.windturbine_id = windturbineId
self.windturbine_name = windturbineName
self.response_data = {}
self.main_url = "https://mijn.windcentrale.nl/api/v0/livedata"

def __get_data(self):
"Collect data form url"
get_url = '{}?projects={}'.format(self.main_url, self.windturbine_id)
get_url = 'https://{}/api/v0/livedata?projects={}'.format(self.wind.base_url, self.windturbine_id)
return requests.get(get_url, headers=self.wind.tokens, verify=True)

async def update(self):
Expand Down Expand Up @@ -217,11 +224,10 @@ def __init__(self, hass, wind, windturbineId, windturbineName, timeframeType, ti
self.timeframe_offset = timeframeOffset
self.view_type = viewType
self.response_data = {}
self.main_url = "https://mijn.windcentrale.nl/api/v0/sustainable/production"

def __get_data(self):
"Collect data form url"
get_url = '{}/{}?timeframe_type={}&timeframe_offset={}&view_type={}'.format(self.main_url, self.windturbine_id, self.timeframe_type, self.timeframe_offset, self.view_type)
get_url = 'https://{}/api/v0/sustainable/production/{}?timeframe_type={}&timeframe_offset={}&view_type={}'.format(self.wind.base_url, self.windturbine_id, self.timeframe_type, self.timeframe_offset, self.view_type)
return requests.get(get_url, headers=self.wind.tokens, verify=True)

async def update(self):
Expand Down Expand Up @@ -267,11 +273,11 @@ def __init__(self, wind, hass):
self.wind = wind
self.hass = hass
self.response_data = ""
self.main_url = "https://mijn.windcentrale.nl/api/v0/sustainable/notices"

def __get_data(self):
"Collect data form url"
return requests.get(self.main_url, headers=self.wind.tokens, verify=True)
get_url = 'https://{}/api/v0/sustainable/notices'.format(self.wind.base_url)
return requests.get(get_url, headers=self.wind.tokens, verify=True)

async def update(self):
"Get data ready for home assitant"
Expand Down Expand Up @@ -302,21 +308,33 @@ async def update(self):

class Credentials:
"Checking credentials & collecting windturbines of which you own shares"
def __init__(self, hass, email, password):
def __init__(self, hass, email, password, platform):
self.hass = hass
self.email = email
self.password = password
self.platform = platform
self.authorization_header = None
self.projects_list = None

def __get_tokens(self):
boto3_client = boto3.client('cognito-idp', region_name='eu-west-1')
aws = AWSSRP(username=self.email, password=self.password, pool_id='eu-west-1_U7eYBPrBd', client_id='715j3r0trk7o8dqg3md57il7q0', client=boto3_client)
if self.platform == "Windcentrale":
pool_id = WINDCENTRALE_POOL_ID
client_id = WINDCENTRALE_CLIENT_ID
elif self.platform == "Winddelen":
pool_id = WINDDELEN_POOL_ID
client_id = WINDDELEN_CLIENT_ID
aws = AWSSRP(username=self.email, password=self.password, pool_id=pool_id, client_id=client_id, client=boto3_client)
return aws.authenticate_user()

def __get_projects(self):
"Collect windturbine's form projects url"
return requests.get("https://mijn.windcentrale.nl/api/v0/sustainable/projects", headers=self.authorization_header, verify=True)
if self.platform == "Windcentrale":
base_url = WINDCENTRALE_BASE_URL
elif self.platform == "Winddelen":
base_url = WINDDELEN_BASE_URL
get_url = 'https://{}/api/v0/sustainable/projects'.format(base_url)
return requests.get(get_url, headers=self.authorization_header, verify=True)

async def authenticate_user_credentails(self):
_LOGGER.info('Testing if user credentails are correct')
Expand Down
4 changes: 2 additions & 2 deletions info.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
[![](https://img.shields.io/badge/PayPal-00457C?style=flat&logo=paypal&logoColor=white)](https://paypal.me/jobvankoeveringe)
[![Buy me a coffee](https://img.shields.io/badge/-buy_me_a%C2%A0coffee-gray?logo=buy-me-a-coffee&color=orange)](https://www.buymeacoffee.com/jobvk)

Home Assistant component for the Windcentrale
Home Assistant component for the Windcentrale & Winddelen

The `Windcentrale` component is a Home Assistant component which lets you get sensor and news data from all wind turbines.

The official website https://www.windcentrale.nl
The official websites are https://www.windcentrale.nl and https://winddelen.nl

## Example

Expand Down
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
boto3==1.26.70
pycognito==2022.12.0
boto3==1.26.147
pycognito==2023.5.0

0 comments on commit 74b53f8

Please sign in to comment.