MycroftAI / skill-homeassistant

Mycroft Skill/Integration for Homeassistant
GNU Lesser General Public License v3.0
114 stars 62 forks source link

Fix NoneType error when no url match the regex #86

Closed Tony763 closed 2 years ago

Tony763 commented 2 years ago

Description

Fix for #85

re.search return None if no match is found.

Type of PR

Testing

I will add unittest to #77 tonight

Under line Know it, but forget.

Tony763 commented 2 years ago

@krisgesling, could you please check? Tested by @Y0ngg4n.

We can return only group(1) but firstly we have to check if anything was found.

Scholar mistake :smile:

Tony763 commented 2 years ago

Sure, I will add them tomorrow and maybe alongside with update to regex to allow ipv6 mach also shortened format ( 2041:0:140F::875B:131B).

Tony763 commented 2 years ago

Hi @Y0ngg4n, could You test this PR again? I reworked a IP address validation function. @krisgesling Ipv6 reworked, unittests added.

goldyfruit commented 2 years ago

Without this PR, the skill doesn't load on a fresh install.

2021-10-27 21:46:46.159 | ERROR    |     1 | mycroft.skills.skill_loader:_create_skill_instance:313 | Skill initialization failed with TypeError('expected string or bytes-like object')
Traceback (most recent call last):
  File "/home/mycroft/core/mycroft/skills/skill_loader.py", line 307, in _create_skill_instance
    self.instance.initialize()
  File "/opt/mycroft/skills/skill-homeassistant.mycroftai/__init__.py", line 93, in initialize
    self._setup()
  File "/opt/mycroft/skills/skill-homeassistant.mycroftai/__init__.py", line 34, in _setup
    ip_address = check_url(self.settings.get('host'))
  File "/opt/mycroft/skills/skill-homeassistant.mycroftai/ha_client.py", line 38, in check_url
    matches = re.search(ip_regex, ip)
  File "/usr/lib/python3.7/re.py", line 183, in search
    return _compile(pattern, flags).search(string)
TypeError: expected string or bytes-like object
Tony763 commented 2 years ago

Hi @krisgesling, I rebased PR, could You try to readd secure label?