Add user agent check to frontend (#955)

* Add user agent check to frontend

* Remove auto generated comment.
This commit is contained in:
Paulus Schoutsen 2018-02-28 10:46:24 -08:00 committed by GitHub
parent 9c6d28fbc4
commit 3fbd5e351e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 27 additions and 1 deletions

View File

@ -1,8 +1,31 @@
"""AUTO-GENERATED. DO NOT MODIFY"""
"""Frontend for Home Assistant."""
import os
from user_agents import parse
FAMILY_MIN_VERSION = {
'Chrome': 54, # Object.values
'Chrome Mobile': 54,
'Firefox': 47, # Object.values
'Firefox Mobile': 47,
'Opera': 41, # Object.values
'Edge': 14, # Array.prototype.includes added in 14
'Safari': 10, # Many features not supported by 9
}
def where():
"""Return path to the frontend."""
return os.path.dirname(__file__)
def version(useragent):
"""Get the version for given user agent."""
useragent = parse(useragent)
# on iOS every browser is a Safari which we support from version 11.
if useragent.os.family == 'iOS':
# Was >= 10, temp setting it to 12 to work around issue #11387
return useragent.os.version[0] >= 12
version = FAMILY_MIN_VERSION.get(useragent.browser.family)
return version and useragent.browser.version[0] >= version

View File

@ -13,5 +13,8 @@ setup(name='home-assistant-frontend',
'hass_frontend.*',
'hass_frontend_es5.*'
]),
install_requires=[
'user-agents==1.1.0',
],
include_package_data=True,
zip_safe=False)