Fix AttributeError: 'NoneType' object has no attribute 'group' with sytadin component (#24652)

* Fix AttributeError: 'NoneType' object has no attribute 'group'

* Update sensor.py
pull/24665/head
foreign-sub 2019-06-20 22:28:39 +02:00 committed by Paulus Schoutsen
parent d8690f426c
commit ecfbfb4527
1 changed files with 9 additions and 3 deletions

View File

@ -124,9 +124,15 @@ class SytadinData:
data = BeautifulSoup(raw_html, 'html.parser')
values = data.select('.barometre_valeur')
self.traffic_jam = re.search(REGEX, values[0].text).group()
self.mean_velocity = re.search(REGEX, values[1].text).group()
self.congestion = re.search(REGEX, values[2].text).group()
parse_traffic_jam = re.search(REGEX, values[0].text)
if parse_traffic_jam:
self.traffic_jam = parse_traffic_jam.group()
parse_mean_velocity = re.search(REGEX, values[1].text)
if parse_mean_velocity:
self.mean_velocity = parse_mean_velocity.group()
parse_congestion = re.search(REGEX, values[2].text)
if parse_congestion:
self.congestion = parse_congestion.group()
except requests.exceptions.ConnectionError:
_LOGGER.error("Connection error")
self.data = None