mirror of
https://git.disroot.org/pranav/pybatmesh.git
synced 2025-03-15 16:24:19 +05:30
added new functions
This commit is contained in:
parent
0e7a69be53
commit
8bf05ba334
@ -26,7 +26,9 @@ class IWD:
|
|||||||
self._proxy = self._bus.get_proxy(IWD_BUS, IWD_ROOT_PATH)
|
self._proxy = self._bus.get_proxy(IWD_BUS, IWD_ROOT_PATH)
|
||||||
|
|
||||||
def get_name_from_path(self, path: str) -> str:
|
def get_name_from_path(self, path: str) -> str:
|
||||||
"""returns device or adapter name when d-bus path is given as arg"""
|
"""
|
||||||
|
returns device or adapter name when d-bus path is given as arg
|
||||||
|
"""
|
||||||
proxy = self._bus.get_proxy(IWD_BUS, path)
|
proxy = self._bus.get_proxy(IWD_BUS, path)
|
||||||
return proxy.Name
|
return proxy.Name
|
||||||
|
|
||||||
@ -37,7 +39,7 @@ class IWD:
|
|||||||
proxy = self._bus.get_proxy(IWD_BUS, i)
|
proxy = self._bus.get_proxy(IWD_BUS, i)
|
||||||
if proxy.Name == name:
|
if proxy.Name == name:
|
||||||
return i
|
return i
|
||||||
# If no devices were found, return None
|
# If no devices were found, return None
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def get_adapter_path_from_name(self, name: str) -> str:
|
def get_adapter_path_from_name(self, name: str) -> str:
|
||||||
@ -47,7 +49,7 @@ class IWD:
|
|||||||
proxy = self._bus.get_proxy(IWD_BUS, i)
|
proxy = self._bus.get_proxy(IWD_BUS, i)
|
||||||
if proxy.Name == name:
|
if proxy.Name == name:
|
||||||
return i
|
return i
|
||||||
# If no adapters were found
|
# If no adapters were found
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def get_all_device_paths(self) -> list:
|
def get_all_device_paths(self) -> list:
|
||||||
@ -101,7 +103,7 @@ class IWD:
|
|||||||
class Device:
|
class Device:
|
||||||
"""
|
"""
|
||||||
control devices with iwd
|
control devices with iwd
|
||||||
name: name of device
|
name: name of device (str)
|
||||||
adapter: name of adapter (str)
|
adapter: name of adapter (str)
|
||||||
"""
|
"""
|
||||||
|
|
||||||
@ -114,10 +116,42 @@ class Device:
|
|||||||
adapter_path = self._proxy.Adapter
|
adapter_path = self._proxy.Adapter
|
||||||
self.adapter = self._iwd.get_name_from_path(adapter_path)
|
self.adapter = self._iwd.get_name_from_path(adapter_path)
|
||||||
|
|
||||||
|
def is_powered_on(self) -> bool:
|
||||||
|
"""returns True if devie is powered on"""
|
||||||
|
return self._proxy.Powered
|
||||||
|
|
||||||
|
def power_on(self):
|
||||||
|
"""Turn on the device and reload the proxy"""
|
||||||
|
self._proxy.Powered = True
|
||||||
|
self.reload()
|
||||||
|
|
||||||
|
def power_off(self):
|
||||||
|
"""Turn off the device and reload the proxy"""
|
||||||
|
self._proxy.Powered = False
|
||||||
|
self.reload()
|
||||||
|
|
||||||
def reload(self):
|
def reload(self):
|
||||||
"""reload the proxy after changing mode"""
|
"""reload the proxy after changing mode"""
|
||||||
self._proxy = self._bus.get_proxy(IWD_BUS, self._path)
|
self._proxy = self._bus.get_proxy(IWD_BUS, self._path)
|
||||||
|
|
||||||
|
def is_adhoc_started(self):
|
||||||
|
"""
|
||||||
|
Returns True if an adhoc network is started on this device.
|
||||||
|
Returns None if device is not powered on or not in ad-hoc mode.
|
||||||
|
"""
|
||||||
|
if self.is_powered_on() and self.get_mode() == "ad-hoc":
|
||||||
|
return self._proxy.Started
|
||||||
|
# If above condition is not true, return None
|
||||||
|
return None
|
||||||
|
|
||||||
|
def is_ap_started(self):
|
||||||
|
"""
|
||||||
|
Same as is_adhoc_started(), but for ap
|
||||||
|
"""
|
||||||
|
if self.is_powered_on() and self.get_mode == "ap":
|
||||||
|
return self._proxy.Started
|
||||||
|
return None
|
||||||
|
|
||||||
def get_mode(self) -> str:
|
def get_mode(self) -> str:
|
||||||
"""
|
"""
|
||||||
returns the mode in which the device is in
|
returns the mode in which the device is in
|
||||||
@ -130,7 +164,15 @@ class Device:
|
|||||||
self._proxy.Mode = mode
|
self._proxy.Mode = mode
|
||||||
self.reload()
|
self.reload()
|
||||||
|
|
||||||
def start_adhoc_open(self, name):
|
def start_adhoc_open(self, name: str):
|
||||||
|
"""
|
||||||
|
Create ad-hoc network with name, changing mode to ad-hoc
|
||||||
|
if it isn't already on ad-hoc
|
||||||
|
"""
|
||||||
if self.get_mode() != "ad-hoc":
|
if self.get_mode() != "ad-hoc":
|
||||||
self.set_mode("ad-hoc")
|
self.set_mode("ad-hoc")
|
||||||
# TODO: connect to network
|
|
||||||
|
if not self.is_powered_on():
|
||||||
|
self.power_on()
|
||||||
|
|
||||||
|
self._proxy.StartOpen(name)
|
||||||
|
@ -5,7 +5,7 @@ Setup a working BATMAN Advanced network
|
|||||||
with systemd-networkd and iwd
|
with systemd-networkd and iwd
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# Copyright (C) 2021 The Authors
|
# Copyright (C) 2021 The naxalnet Authors
|
||||||
|
|
||||||
# This program is free software: you can redistribute it and/or modify
|
# This program is free software: you can redistribute it and/or modify
|
||||||
# it under the terms of the GNU General Public License as published by
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
Loading…
x
Reference in New Issue
Block a user