Skip to content

Commit ab811cc

Browse files
feat: long-run prod patch
1 parent 5db04be commit ab811cc

File tree

4 files changed

+17
-7
lines changed

4 files changed

+17
-7
lines changed

core/strategies/eye/picamera_strategy.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,5 +45,4 @@ def get_frame(self) -> numpy.ndarray:
4545
logger.error(
4646
"An error occurred while capturing the frame: %s", error)
4747
raise RuntimeError from error
48-
return cv2.rotate(frame,
49-
cv2.ROTATE_90_COUNTERCLOCKWISE)
48+
return frame

core/strategies/wifi/ipaddress_strategy.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
The strategy which searches for IP addresses.
33
"""
44
from core.strategies.wifi.base_wifi_strategy import BaseWiFiStrategy
5-
from core.utils.datatypes import WiFiStrategyResult
5+
from core.utils.datatypes import ConnectedDeviceResult, WiFiStrategyResult
66
from core.utils.logger import get_logger
7-
from core.utils.program_launcher import PingCommands, run_program
7+
from core.utils.program_launcher import ArpScanCommands, PingCommands, run_program
88

99
# Add logging support.
1010
logger = get_logger(__name__)
@@ -37,3 +37,12 @@ def check_protectors(self) -> WiFiStrategyResult:
3737
return WiFiStrategyResult(protector, True)
3838
logger.debug("No protectors found.")
3939
return WiFiStrategyResult(None, False)
40+
41+
# Internal methods
42+
def _get_all_connected(self) -> list[ConnectedDeviceResult]:
43+
"""This method returns a list of addresses of the clients connected to the network."""
44+
output = run_program(ArpScanCommands.GET_CONNECTED_IP_ADDRESSES)
45+
ip_addrs = output.split('\n')
46+
ip_addrs = ip_addrs[:-1]
47+
logger.debug("Connected devices: %s", str(ip_addrs))
48+
return [ConnectedDeviceResult(mac_addr.upper()) for mac_addr in ip_addrs]

core/utils/program_launcher.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from enum import Enum
66

77

8-
class ICommand(Enum, str):
8+
class ICommand(str, Enum):
99
"""Interface for program commands."""
1010

1111

@@ -15,6 +15,8 @@ class ArpScanCommands(ICommand):
1515
INSTALL_PROGRAM = "sudo apt-get install arp-scan"
1616
GET_CONNECTED_MAC_ADDRESSES = "sudo arp-scan --localnet "\
1717
"| grep -o -E '([[:xdigit:]]{1,2}:){5}[[:xdigit:]]{1,2}'"
18+
GET_CONNECTED_IP_ADDRESSES = "sudo arp-scan --localnet "\
19+
"| grep -oE '([0-9]{1,3}\.){3}[0-9]{1,3}'"
1820

1921

2022
class PingCommands(ICommand):

hss.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
from core.strategies.eye.picamera_strategy import PiCameraStrategy
1515
from core.strategies.notifier.telegram_strategy import TelegramStrategy
1616
from core.strategies.notifier.whatsapp_strategy import WhatsappStrategy
17-
from core.strategies.wifi.admin_panel_strategy import AdminPanelStrategy
17+
from core.strategies.wifi.ipaddress_strategy import IpAddressStrategy
1818
from core.utils.datatypes import Protector, TelegramReciever
1919
from core.utils.fileio_adaptor import upload_to_fileio
2020

@@ -44,7 +44,7 @@ def main():
4444
reciever['chat_id']))
4545

4646
# Create a Protector within IpAddressStrategy.
47-
network_strategy = AdminPanelStrategy(strategy_config['admin_panel_strategy'])
47+
network_strategy = IpAddressStrategy()
4848
for protector in config['protectors']:
4949
network_strategy.add_protector(Protector(protector['name'],
5050
protector['address']))

0 commit comments

Comments
 (0)