Skip to content

Added port profiles and PoE settings #15

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion alerts.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def print_alert( alert ):
sys.stdout.write( '\n' )

def main():
omada = Omada()
omada = Omada('omada.cfg')
omada.login()

print_header()
Expand Down
2 changes: 1 addition & 1 deletion clients.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def print_client( client ):
sys.stdout.write( '\n' )

def main():
omada = Omada()
omada = Omada('omada.cfg')
omada.login()

print_header()
Expand Down
2 changes: 1 addition & 1 deletion devices.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def print_device( device ):
sys.stdout.write( '\n' )

def main():
omada = Omada()
omada = Omada('omada.cfg')
omada.login()

print_header()
Expand Down
2 changes: 1 addition & 1 deletion events.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def print_event( event ):
sys.stdout.write( '\n' )

def main():
omada = Omada()
omada = Omada('omada.cfg')
omada.login()

print_header()
Expand Down
2 changes: 1 addition & 1 deletion led.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def main():
print( f"usage: {sys.argv[0]} [on|off]" )
return

omada = Omada()
omada = Omada('omada.cfg')
omada.login()

settings = omada.getSiteSettings()
Expand Down
34 changes: 34 additions & 0 deletions omada/omada.py
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,41 @@ def getSiteSettings(self, site=None):
##
def setSiteSettings(self, settings, site=None):
return self.__patch( f'/sites/{self.__findKey(site)}/setting', json=settings )

##
## Returns the list of profiles for the given site.
##
def getProfiles(self, site=None):
return self.__geterator( f'/sites/{self.__findKey(site)}/setting/lan/profiles' )

##
## Returns the settings for a profile for a given site.
##
def getProfileSettings(self, profileId, site=None):
profiles = self.getProfiles()
for profile in profiles:
if profile['id'] == profileId:
return profile

return

##
## Returns the profile Id of a profile for a given site.
##
def getProfileId(self, profileName, site=None):
profiles = self.getProfiles()
for profile in profiles:
if profile['name'] == profileName:
return profile['id']

return

##
## Push back the settings for the profile
##
def setProfileSettings(self, profileId, settings, site=None):
return self.__patch( f'/sites/{self.__findKey(site)}/setting/lan/profiles/{profileId}', json=settings)

##
## Returns the list of timerange profiles for the given site.
##
Expand Down
34 changes: 34 additions & 0 deletions poe.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/usr/bin/env python3

import sys, collections
from omada import Omada

def format_poe(poe):
if poe == 0:
return 'Disabled'
elif poe == 1:
return 'Enabled'
elif poe == 2:
return "Keep the Device's Settings"

def main():
if len(sys.argv) > 2 and sys.argv[2] not in ("0", "1", "2"):
print( f"usage: {sys.argv[0]} [profile name] [0|1|2]" )
return

omada = Omada('omada.cfg')
omada.login()

if len(sys.argv) > 2:
profileId = omada.getProfileId(sys.argv[1])
settings = omada.getProfileSettings(profileId)
settings['poe'] = sys.argv[2]
omada.setProfileSettings(profileId, settings)

settings = omada.getProfileSettings(profileId)
print( f"Changed the poe setting for profile {settings['name']} to {format_poe(settings['poe'])}.")

omada.logout()

if __name__ == '__main__':
main()
75 changes: 75 additions & 0 deletions profiles.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
#!/usr/bin/env python3

import sys, collections
from omada import Omada

FIELDDEF = collections.OrderedDict([
('id', ('ID', 30)),
('name', ('NAME', 30)),
('poe', ('POE', 30)),
('nativeNetworkId', ('Native Network ID', 30)),
])

def format_poe (poe):
if poe == 0:
return 'Disabled'
elif poe == 1:
return 'Enabled'
elif poe == 2:
return 'Keep the device settings'
else:
return 'Unknown'


def print_header():

if sys.stdout.isatty():
sys.stdout.write( '\33[1m' )

for key in FIELDDEF:
text,width = FIELDDEF[key]
sys.stdout.write( text.ljust(abs(width)) )

if sys.stdout.isatty():
sys.stdout.write( '\33[0m' )

sys.stdout.write( '\n' )

def print_profile ( profile ):
for key in profile:
if key == 'poe':
profile[key] = format_poe( profile['poe'])

for key in FIELDDEF:
text = profile[key] if key in profile else '--'
if not isinstance(text, str): text = str(text)

width = FIELDDEF[key][1]

if len(text) >= abs(width):
text = text[0:abs(width)-4] + '... '
elif width > 0:
text = text.ljust(abs(width))
else:
text = text.rjust(abs(width)-1)

sys.stdout.write( text )

sys.stdout.write( '\n' )


def main():
omada = Omada('omada.cfg')
omada.login()

print_header()

profiles = omada.getProfiles()

for profile in profiles:
print_profile( profile )

omada.logout()

if __name__ == '__main__':
main()