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

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

* Update sensor.py
This commit is contained in:
foreign-sub 2019-06-20 22:28:39 +02:00 committed by Paulus Schoutsen
parent d8690f426c
commit ecfbfb4527

View File

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