Skip to content

Commit

Permalink
release 0.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
rgerbranda committed Aug 12, 2024
1 parent 484587a commit 9b11500
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 28 deletions.
27 changes: 17 additions & 10 deletions custom_components/rbfa/API.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ def __init__(self, hass, my_api):
self.team = my_api.data['team']


def __get_url(self, operation, value):
def xx__get_url(self, operation, value):
with open(operation + ".txt", 'r') as fson:
rj = json.load(fson)
return rj

def xx__get_url(self, operation, value):
def __get_url(self, operation, value):
try:
main_url = 'https://datalake-prod2018.rbfa.be/graphql'
url = '{}?operationName={}&variables={{"{}":"{}","language":"nl"}}&extensions={{"persistedQuery":{{"version":1,"sha256Hash":"{}"}}}}'.format(
Expand All @@ -37,7 +37,6 @@ def xx__get_url(self, operation, value):
value,
HASHES[operation]
)
# _LOGGER.debug(url)
response = requests.get(url)
if response.status_code != 200:
_LOGGER.debug('Invalid response from server for collection data')
Expand Down Expand Up @@ -95,6 +94,13 @@ async def update(self, my_api):
else:
self.show_ranking = True

if 'show_referee' in my_api.options:
self.show_referee = my_api.options['show_referee']
elif 'show_referee' in my_api.data:
self.show_referee = my_api.data['show_referee']
else:
self.show_referee = True

self.collections = [];
_LOGGER.debug('duration: %r', self.duration)
_LOGGER.debug('show ranking: %r', self.show_ranking)
Expand All @@ -111,7 +117,6 @@ async def update(self, my_api):
previous = None

self.collections = []
ranking = []
referee = None

for item in r['data']['teamCalendar']:
Expand All @@ -124,10 +129,11 @@ async def update(self, my_api):
match['postalCode'],
match['city'],
)
officials = r['data']['matchDetail']['officials']
for x in officials:
if x['function'] == 'referee':
referee = f"{x['firstName']} {x['lastName']}"
if self.show_referee:
officials = r['data']['matchDetail']['officials']
for x in officials:
if x['function'] == 'referee':
referee = f"{x['firstName']} {x['lastName']}"
else:
location = None

Expand Down Expand Up @@ -169,7 +175,8 @@ async def update(self, my_api):
}
if self.show_ranking:
await self.get_ranking('upcoming')
await self.get_ranking('lastmatch')
if previous != None:
await self.get_ranking('lastmatch')

summary = '[' + item['state'] + '] ' + item['homeTeam']['name'] + ' - ' + item['awayTeam']['name']
description = item['series']['name']
Expand Down Expand Up @@ -216,4 +223,4 @@ async def get_ranking (self, tag):
if rank['teamId'] == self.matchdata[tag]['hometeamid']:
self.matchdata[tag]['hometeamposition'] = rank['position']
if rank['teamId'] == self.matchdata[tag]['awayteamid']:
self.matchdata[tag]['awayteamposition'] = rank['position']
self.matchdata[tag]['awayteamposition'] = rank['position']
10 changes: 10 additions & 0 deletions custom_components/rbfa/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ async def async_step_user(self, user_input):
),
),
vol.Required('show_ranking', default=True): bool,
vol.Required('show_referee', default=True): bool,
}
)

Expand Down Expand Up @@ -96,6 +97,14 @@ async def async_step_init(
show_ranking = self.config_entry.data['show_ranking']
else:
show_ranking = True

if 'show_referee' in self.config_entry.options:
show_referee = self.config_entry.options['show_referee']
elif 'show_referee' in self.config_entry.data:
show_referee = self.config_entry.data['show_referee']
else:
show_referee = True

# https://community.home-assistant.io/t/voluptuous-options-flow-validation-for-an-optional-string-how/305538/3
return self.async_show_form(
step_id="init",
Expand All @@ -113,6 +122,7 @@ async def async_step_init(
),
),
vol.Required('show_ranking', default=show_ranking): bool,
vol.Required('show_referee', default=show_referee): bool,
}
),
)
2 changes: 1 addition & 1 deletion custom_components/rbfa/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@
"iot_class": "cloud_polling",
"issue_tracker": "https://github.com/rgerbranda/rbfa/issues",
"requirements": [],
"version": "v0.1.8"
"version": "v0.2.0"
}
40 changes: 25 additions & 15 deletions custom_components/rbfa/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
)
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.config_entries import ConfigEntry

from .const import DOMAIN
from .coordinator import MyCoordinator
Expand Down Expand Up @@ -66,31 +67,40 @@ async def async_setup_entry(
"""Set up RBFA sensor based on a config entry."""
coordinator: MyCoordinator = hass.data[DOMAIN][entry.entry_id]

if 'show_referee' in entry.options:
show_referee = entry.options['show_referee']
elif 'alt_name' in entry.data:
show_referee = entry.data['show_referee']
else:
show_referee = True
_LOGGER.debug('show_referee: %r', show_referee)

all_sensors = []
for description in SENSORS:
all_sensors.append(
RbfaSensor(
coordinator,
description,
entry,
collection='upcoming',
if description.key == 'referee' and show_referee or description.key != 'referee':
all_sensors.append(
RbfaSensor(
coordinator,
description,
entry,
collection='upcoming',
)
)
)
all_sensors.append(
RbfaSensor(
coordinator,
description,
entry,
collection='lastmatch',
all_sensors.append(
RbfaSensor(
coordinator,
description,
entry,
collection='lastmatch',
)
)
)
async_add_entities(
all_sensors
)

class RbfaSensor(RbfaEntity, SensorEntity):
"""Representation of a Sensor."""

_attr_entity_registry_enabled_default = False
def __init__(
self,
coordinator: MyCoordinator,
Expand Down
6 changes: 4 additions & 2 deletions custom_components/rbfa/translations/nl.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"team":"Identiteit van het team",
"alt_name":"Alternatieve naam",
"duration":"Duur van de wedstrijd inclusief rust",
"show_ranking":"Toon uitslagen en rangschikking"
"show_ranking":"Toon uitslagen en rangschikking",
"show_referee":"Toon scheidsrechter"
}
}
},
Expand All @@ -24,7 +25,8 @@
"data":{
"alt_name":"Alternatieve naam",
"duration":"Duur van de wedstrijd inclusief rust",
"show_ranking":"Toon uitslagen en rangschikking"
"show_ranking":"Toon uitslagen en rangschikking",
"show_referee":"Toon scheidsrechter"
}
}
}
Expand Down

0 comments on commit 9b11500

Please sign in to comment.