2020-02-13 21:52:51 -05:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								"""HACS Startup constrains."""
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								# pylint: disable=bad-continuation
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								import os
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								from .const import CUSTOM_UPDATER_LOCATIONS, CUSTOM_UPDATER_WARNING
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								from .helpers.misc import version_left_higher_then_right
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2020-04-09 21:29:27 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								from custom_components.hacs.globals import get_hacs
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2020-05-21 18:48:00 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								MINIMUM_HA_VERSION = "0.110.0"
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-13 21:52:51 -05:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2020-05-21 18:48:00 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								def check_constrains():
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-13 21:52:51 -05:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    """Check HACS constrains."""
							 | 
						
					
						
							
								
									
										
										
										
											2020-04-09 21:29:27 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    if not constrain_translations():
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-13 21:52:51 -05:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        return False
							 | 
						
					
						
							
								
									
										
										
										
											2020-04-09 21:29:27 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    if not constrain_custom_updater():
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-13 21:52:51 -05:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        return False
							 | 
						
					
						
							
								
									
										
										
										
											2020-04-09 21:29:27 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    if not constrain_version():
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-13 21:52:51 -05:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        return False
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    return True
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2020-04-09 21:29:27 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								def constrain_custom_updater():
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-13 21:52:51 -05:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    """Check if custom_updater exist."""
							 | 
						
					
						
							
								
									
										
										
										
											2020-04-09 21:29:27 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    hacs = get_hacs()
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-13 21:52:51 -05:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    for location in CUSTOM_UPDATER_LOCATIONS:
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        if os.path.exists(location.format(hacs.system.config_path)):
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            msg = CUSTOM_UPDATER_WARNING.format(
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                location.format(hacs.system.config_path)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            )
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            hacs.logger.critical(msg)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            return False
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    return True
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2020-04-09 21:29:27 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								def constrain_version():
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-13 21:52:51 -05:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    """Check if the version is valid."""
							 | 
						
					
						
							
								
									
										
										
										
											2020-04-09 21:29:27 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    hacs = get_hacs()
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-13 21:52:51 -05:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    if not version_left_higher_then_right(hacs.system.ha_version, MINIMUM_HA_VERSION):
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        hacs.logger.critical(
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            f"You need HA version {MINIMUM_HA_VERSION} or newer to use this integration."
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        )
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        return False
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    return True
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2020-04-09 21:29:27 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								def constrain_translations():
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-13 21:52:51 -05:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    """Check if traslations exist."""
							 | 
						
					
						
							
								
									
										
										
										
											2020-04-09 21:29:27 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    hacs = get_hacs()
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-13 21:52:51 -05:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    if not os.path.exists(
							 | 
						
					
						
							
								
									
										
										
										
											2020-05-16 10:34:10 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        f"{hacs.system.config_path}/custom_components/hacs/translations"
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-13 21:52:51 -05:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    ):
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        hacs.logger.critical("You are missing the translations directory.")
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        return False
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    return True
							 |