Skip to content

Commit 9b11500

Browse files
committed
release 0.2.0
1 parent 484587a commit 9b11500

File tree

5 files changed

+57
-28
lines changed

5 files changed

+57
-28
lines changed

custom_components/rbfa/API.py

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@ def __init__(self, hass, my_api):
2222
self.team = my_api.data['team']
2323

2424

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

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

97+
if 'show_referee' in my_api.options:
98+
self.show_referee = my_api.options['show_referee']
99+
elif 'show_referee' in my_api.data:
100+
self.show_referee = my_api.data['show_referee']
101+
else:
102+
self.show_referee = True
103+
98104
self.collections = [];
99105
_LOGGER.debug('duration: %r', self.duration)
100106
_LOGGER.debug('show ranking: %r', self.show_ranking)
@@ -111,7 +117,6 @@ async def update(self, my_api):
111117
previous = None
112118

113119
self.collections = []
114-
ranking = []
115120
referee = None
116121

117122
for item in r['data']['teamCalendar']:
@@ -124,10 +129,11 @@ async def update(self, my_api):
124129
match['postalCode'],
125130
match['city'],
126131
)
127-
officials = r['data']['matchDetail']['officials']
128-
for x in officials:
129-
if x['function'] == 'referee':
130-
referee = f"{x['firstName']} {x['lastName']}"
132+
if self.show_referee:
133+
officials = r['data']['matchDetail']['officials']
134+
for x in officials:
135+
if x['function'] == 'referee':
136+
referee = f"{x['firstName']} {x['lastName']}"
131137
else:
132138
location = None
133139

@@ -169,7 +175,8 @@ async def update(self, my_api):
169175
}
170176
if self.show_ranking:
171177
await self.get_ranking('upcoming')
172-
await self.get_ranking('lastmatch')
178+
if previous != None:
179+
await self.get_ranking('lastmatch')
173180

174181
summary = '[' + item['state'] + '] ' + item['homeTeam']['name'] + ' - ' + item['awayTeam']['name']
175182
description = item['series']['name']
@@ -216,4 +223,4 @@ async def get_ranking (self, tag):
216223
if rank['teamId'] == self.matchdata[tag]['hometeamid']:
217224
self.matchdata[tag]['hometeamposition'] = rank['position']
218225
if rank['teamId'] == self.matchdata[tag]['awayteamid']:
219-
self.matchdata[tag]['awayteamposition'] = rank['position']
226+
self.matchdata[tag]['awayteamposition'] = rank['position']

custom_components/rbfa/config_flow.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ async def async_step_user(self, user_input):
4747
),
4848
),
4949
vol.Required('show_ranking', default=True): bool,
50+
vol.Required('show_referee', default=True): bool,
5051
}
5152
)
5253

@@ -96,6 +97,14 @@ async def async_step_init(
9697
show_ranking = self.config_entry.data['show_ranking']
9798
else:
9899
show_ranking = True
100+
101+
if 'show_referee' in self.config_entry.options:
102+
show_referee = self.config_entry.options['show_referee']
103+
elif 'show_referee' in self.config_entry.data:
104+
show_referee = self.config_entry.data['show_referee']
105+
else:
106+
show_referee = True
107+
99108
# https://community.home-assistant.io/t/voluptuous-options-flow-validation-for-an-optional-string-how/305538/3
100109
return self.async_show_form(
101110
step_id="init",
@@ -113,6 +122,7 @@ async def async_step_init(
113122
),
114123
),
115124
vol.Required('show_ranking', default=show_ranking): bool,
125+
vol.Required('show_referee', default=show_referee): bool,
116126
}
117127
),
118128
)

custom_components/rbfa/manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@
88
"iot_class": "cloud_polling",
99
"issue_tracker": "https://github.com/rgerbranda/rbfa/issues",
1010
"requirements": [],
11-
"version": "v0.1.8"
11+
"version": "v0.2.0"
1212
}

custom_components/rbfa/sensor.py

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
)
99
from homeassistant.core import HomeAssistant
1010
from homeassistant.helpers.entity_platform import AddEntitiesCallback
11+
from homeassistant.config_entries import ConfigEntry
1112

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

70+
if 'show_referee' in entry.options:
71+
show_referee = entry.options['show_referee']
72+
elif 'alt_name' in entry.data:
73+
show_referee = entry.data['show_referee']
74+
else:
75+
show_referee = True
76+
_LOGGER.debug('show_referee: %r', show_referee)
77+
6978
all_sensors = []
7079
for description in SENSORS:
71-
all_sensors.append(
72-
RbfaSensor(
73-
coordinator,
74-
description,
75-
entry,
76-
collection='upcoming',
80+
if description.key == 'referee' and show_referee or description.key != 'referee':
81+
all_sensors.append(
82+
RbfaSensor(
83+
coordinator,
84+
description,
85+
entry,
86+
collection='upcoming',
87+
)
7788
)
78-
)
79-
all_sensors.append(
80-
RbfaSensor(
81-
coordinator,
82-
description,
83-
entry,
84-
collection='lastmatch',
89+
all_sensors.append(
90+
RbfaSensor(
91+
coordinator,
92+
description,
93+
entry,
94+
collection='lastmatch',
95+
)
8596
)
86-
)
8797
async_add_entities(
8898
all_sensors
8999
)
90100

91101
class RbfaSensor(RbfaEntity, SensorEntity):
92102
"""Representation of a Sensor."""
93-
103+
_attr_entity_registry_enabled_default = False
94104
def __init__(
95105
self,
96106
coordinator: MyCoordinator,

custom_components/rbfa/translations/nl.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
"team":"Identiteit van het team",
99
"alt_name":"Alternatieve naam",
1010
"duration":"Duur van de wedstrijd inclusief rust",
11-
"show_ranking":"Toon uitslagen en rangschikking"
11+
"show_ranking":"Toon uitslagen en rangschikking",
12+
"show_referee":"Toon scheidsrechter"
1213
}
1314
}
1415
},
@@ -24,7 +25,8 @@
2425
"data":{
2526
"alt_name":"Alternatieve naam",
2627
"duration":"Duur van de wedstrijd inclusief rust",
27-
"show_ranking":"Toon uitslagen en rangschikking"
28+
"show_ranking":"Toon uitslagen en rangschikking",
29+
"show_referee":"Toon scheidsrechter"
2830
}
2931
}
3032
}

0 commit comments

Comments
 (0)