Initialize the e-paper display.
(self)
| 999 | logger.warning("Could not add local MAC to blacklist: MAC address not found") |
| 1000 | |
| 1001 | |
| 1002 | |
| 1003 | def get_raspberry_mac(self): |
| 1004 | """Get the MAC address of the primary network interface (usually wlan0 or eth0).""" |
| 1005 | try: |
| 1006 | # First try wlan0 (wireless interface) |
| 1007 | result = subprocess.run(['cat', '/sys/class/net/wlan0/address'], |
| 1008 | capture_output=True, text=True) |
| 1009 | if result.returncode == 0 and result.stdout.strip(): |
| 1010 | return result.stdout.strip().lower() |
| 1011 | |
| 1012 | # If wlan0 fails, try eth0 (ethernet interface) |
| 1013 | result = subprocess.run(['cat', '/sys/class/net/eth0/address'], |
| 1014 | capture_output=True, text=True) |
| 1015 | if result.returncode == 0 and result.stdout.strip(): |
| 1016 | return result.stdout.strip().lower() |
| 1017 | |
| 1018 | logger.warning("Could not find MAC address for wlan0 or eth0") |
| 1019 | return None |
| 1020 | |
| 1021 | except Exception as e: |
| 1022 | logger.error(f"Error getting Raspberry Pi MAC address: {e}") |
| 1023 | return None |
| 1024 | |
| 1025 | |
| 1026 | |
| 1027 | def setup_environment(self, clear_console=False): |
| 1028 | """Setup the environment with the necessary directories and files.""" |
| 1029 | if clear_console: |
| 1030 | os.system('cls' if os.name == 'nt' else 'clear') |
| 1031 | self.create_directories() # Create all necessary directories first |
| 1032 | self.save_config() |
| 1033 | if self._pager_mode: |
| 1034 | # On Pager: try to regenerate actions.json (works if deps are available), |
| 1035 | # fall back to loading existing file if generation fails. |
| 1036 | if not os.path.exists(self.actions_file): |
| 1037 | try: |
| 1038 | self.generate_actions_json() |
| 1039 | except Exception as e: |
| 1040 | logger.warning(f"Could not generate actions.json: {e}") |
| 1041 | self._load_status_list_from_actions_json() |
| 1042 | else: |
| 1043 | # Skip costly re-import of every action module if actions.json |
| 1044 | # is already up to date (same set of .py files in actions/). |
| 1045 | self._generate_actions_json_if_needed() |
| 1046 | self.delete_webconsolelog() |
| 1047 | self.initialize_csv() |
| 1048 | self.initialize_epd_display() |
| 1049 | |
| 1050 | def create_directories(self): |
| 1051 | """Create all necessary directories for the application.""" |
| 1052 | directories_to_create = [ |
| 1053 | self.configdir, |
| 1054 | self.datadir, |
| 1055 | self.actions_dir, |
| 1056 | self.webdir, |
| 1057 | self.resourcesdir, |
| 1058 | self.backupbasedir, |
no test coverage detected