def test_get_interfaces_no_wlan(): """Test the get_interfaces functions with no 'wlan' interfaces.""" interfaces = get_interfaces(keep_wlan=False) for x in interfaces: assert not x.startswith("wlan")
def test_get_interfaces_no_eth(): """Test the get_interfaces functions with no 'eth' interfaces.""" interfaces = get_interfaces(keep_eth=False) for x in interfaces: assert not x.startswith("eth")
def test_get_interfaces_default(): """Test the get_interfaces function with default parameters.""" interfaces = get_interfaces() assert isinstance(interfaces, list) assert "lo" not in interfaces assert "sit0" not in interfaces
def wifi_info() -> List: """Get a list of WiFi details for all wlan interfaces. Returns: List: For each interface, a dictionary of details is added to the list Keys of the dictionary are: interface: the interface if ap: clients: the number of clients currently connected ssid: the ssid of the ap password: the password of the ap if dhcp: state: either the SSID currently connected to or False state_boolean: boolean value for state. True or False if state: address: the IPV4 address ssid: the ssid of the dhcp interface password: the password of the dhcp interface """ logger.debug("getting wifi information") wlan_interfaces = get_interfaces(keep_eth=False) wifi = [] session = get_session() for w_interface in wlan_interfaces: try: info = {} interface = session.query(Interface).filter_by( interface=w_interface).one() info["interface"] = interface if interface.state == "ap": info["clients"] = wifi_ap_clients(interface.interface) info["ssid"] = interface.credentials[0].name info["password"] = interface.credentials[0].password else: info["state"] = wifi_dhcp_info(interface.interface) if info["state"] is False: info["state_boolean"] = False else: info["state_boolean"] = True if w_interface in netifaces.interfaces(): address = netifaces.ifaddresses(w_interface) info["address"] = address[netifaces.AF_INET][0]["addr"] if interface.credentials: info["ssid"] = interface.credentials[0].name info["password"] = interface.credentials[0].password wifi.append(info) except NoResultFound: pass session.close() return wifi
def refresh_interfaces(): """Refresh all interfaces. Update with current information.""" session = get_session() ap_present = False interfaces = get_interfaces() # update all interfaces.active to be False by default session.query(Interface).update({Interface.is_active: False}) for my_interface in interfaces: try: interface = session.query(Interface).filter_by( interface=my_interface).one() interface.is_active = True # see if there is an interface that is configured for an ap if interface.state == "ap": ap_present = True # must be a new interface so lets add it except NoResultFound: new_interface = Interface(my_interface) new_interface.is_active = True new_interface.is_for_fm = False new_interface.state = "dhcp" session.add(new_interface) session.commit() session.close() if ap_present: set_ap_mode() else: set_wpa_mode()
def first_setup(standalone): # noqa: C901 """First time setup. Load required data.""" # pylint: disable=too-many-statements,too-many-locals click.echo("First time setup") session = get_session() try: system = session.query(SystemSetup).one() except NoResultFound: system = SystemSetup() session.add(system) if system.first_setup: click.echo("Setup has already been run") if not click.confirm("Do you want to run first time setup again?"): session.close() return system.standalone_configuration = standalone system.first_setup = True system.first_setup_time = datetime.now() session.commit() session.close() if standalone: if click.confirm("Do you want to change the device name?"): name = click.prompt("Please enter a new device name") set_device_name(name) if click.confirm("Do you want to set hardware informations?"): hardware_version = click.prompt( "Enter the hardware version", default="pi3_0001" ) gb_count = click.prompt( "Enter the number of grainbin reader chips on the board", default=0 ) set_hardware_info(hardware_version, gb_count) if click.confirm("Do you want to set the sensor information?"): current_sensors = get_connected_sensors(values=True) click.echo("Current sensor information: ") for index, sensor in enumerate(current_sensors): click.echo( f"{index + 1}. Sensor: {sensor['name']} Temperature: {sensor['temperature']}" ) interior_sensor = click.prompt( "Select which sensor is the internal temperature", default=1 ) exterior_sensor = click.prompt( "Select which sensor is the external temperature", default=2 ) set_sensor_info(interior_sensor, exterior_sensor) if click.confirm("Do you want to set the software information?"): software_version = click.prompt("Enter the software version") set_software_info(software_version) if standalone: if click.confirm("Do you want to set details for the interfaces?"): interfaces = get_interfaces() x = 1 interface_details = [] for interface in interfaces: click.echo(f"{x}. {interface}") x = x + 1 interface_details.append(get_interface_details(interface)) set_interfaces(interface_details) initialize_device()