Skip to content

Commit

Permalink
Represent PoE state using dataclass
Browse files Browse the repository at this point in the history
  • Loading branch information
stveit committed Jun 6, 2023
1 parent d3c9131 commit 5d97c40
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions python/nav/portadmin/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@
#
"""Interface definition for PortAdmin management handlers"""
import time
from typing import List, Tuple, Dict, Any, Sequence
from typing import List, Tuple, Dict, Any, Sequence, Union
import logging
from dataclasses import dataclass

from nav.models import manage
from nav.portadmin.vlan import FantasyVlan
Expand All @@ -25,6 +26,17 @@
_logger = logging.getLogger(__name__)


@dataclass
class PoeState:
"""Class for defining PoE states.
`state` is the value used on the device itself.
`name` is a human readable name for the state
"""

state: Union[str, int]
name: str


class ManagementHandler:
"""Defines a common interface for all types of PortAdmin management handlers.
Expand Down Expand Up @@ -278,17 +290,17 @@ def is_configurable(self) -> bool:
return False
return True

def get_poe_state_options(self) -> Tuple[str, ...]:
def get_poe_state_options(self) -> Tuple[PoeState, ...]:
"""Returns the available options for enabling/disabling PoE on this netbox"""
raise NotImplementedError

def set_poe_state(self, interface: manage.Interface, state: str):
def set_poe_state(self, interface: manage.Interface, state: PoeState):
"""Set state for enabling/disabling PoE on this interface.
Available options should be retrieved using `get_poe_state_options`
"""
raise NotImplementedError

def get_poe_state(self, interface: manage.Interface) -> str:
def get_poe_state(self, interface: manage.Interface) -> PoeState:
"""Returns current PoE state of this interface"""
raise NotImplementedError

Expand Down

0 comments on commit 5d97c40

Please sign in to comment.