-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from JohNan/johnan/network-info
Adds network info and fixes error with multiple event in same payload
- Loading branch information
Showing
6 changed files
with
137 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -141,3 +141,5 @@ dmypy.json | |
# Pyre type checker | ||
.pyre/ | ||
/.tool-versions | ||
|
||
/pyflichub/version.py |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
from typing import List | ||
|
||
|
||
class WifiInfo: | ||
state: str | ||
ssid: str | ||
|
||
def __init__(self, connected, ip, mac): | ||
self.connected = connected | ||
self.ip = ip | ||
self.mac = mac | ||
|
||
|
||
class EthernetInfo: | ||
def __init__(self, connected, ip, mac): | ||
self.connected = connected | ||
self.ip = ip | ||
self.mac = mac | ||
|
||
|
||
class DhcpInfo: | ||
def __init__(self, wifi=None, ethernet=None): | ||
self.wifi = WifiInfo(**wifi) if wifi else None | ||
self.ethernet = EthernetInfo(**ethernet) if ethernet else None | ||
|
||
|
||
class _WifiState: | ||
def __init__(self, state, ssid): | ||
self.state = state | ||
self.ssid = ssid | ||
|
||
|
||
def _decode_ssid(ssid_list): | ||
return ''.join(chr(byte) for byte in ssid_list) | ||
|
||
|
||
class Network: | ||
def __init__(self, dhcp, wifi_state=None): | ||
self._dhcp = DhcpInfo(**dhcp) | ||
self._dhcp.wifi.state = wifi_state.get('state', None) if wifi_state else None | ||
self._dhcp.wifi.ssid = _decode_ssid(wifi_state.get('ssid', None)) if wifi_state else None | ||
|
||
def has_wifi(self) -> bool: | ||
return self._dhcp.wifi is not None | ||
|
||
def has_ethernet(self) -> bool: | ||
return self._dhcp.ethernet is not None | ||
|
||
@property | ||
def wifi(self) -> WifiInfo: | ||
return self._dhcp.wifi | ||
|
||
@property | ||
def ethernet(self) -> EthernetInfo: | ||
return self._dhcp.ethernet | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters