Skip to content

Commit

Permalink
Update switch.py (#24)
Browse files Browse the repository at this point in the history
Add schema, use f-strings
  • Loading branch information
foreign-sub authored and stilllman committed Sep 30, 2019
1 parent b7ada19 commit 6bc5d1e
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions aiofreepybox/api/switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,17 @@ class Switch:
def __init__(self, access):
self._access = access

switch_duplex = [
'auto',
'full',
'half'
]

switch_port_configuration_schema = {
'duplex': switch_duplex[0],
'speed': ''
}

async def get_status(self):
'''
Get Switch status
Expand All @@ -13,16 +24,16 @@ async def get_port_conf(self, port_id):
'''
Get port_id Port configuration
'''
return await self._access.get('switch/port/{0}'.format(port_id))
return await self._access.get(f'switch/port/{port_id}')

async def set_port_conf(self, port_id, conf):
async def set_port_conf(self, port_id, switch_port_configuration=switch_port_configuration_schema):
'''
Update port_id Port configuration with conf dictionary
'''
await self._access.put('switch/port/{0}'.format(port_id), conf)
await self._access.put(f'switch/port/{port_id}', switch_port_configuration)

async def get_port_stats(self, port_id):
'''
Get port_id Port stats
'''
return await self._access.get('switch/port/{0}/{1}'.format(port_id, 'stats'))
return await self._access.get(f'switch/port/{port_id}/stats')

0 comments on commit 6bc5d1e

Please sign in to comment.