46 lines
1.5 KiB
Python
46 lines
1.5 KiB
Python
import logging
|
|
import uuid
|
|
from datetime import datetime
|
|
import logging
|
|
import click
|
|
|
|
from iottb.utils.string_processing import make_canonical_name
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
class DeviceMetadata:
|
|
def __init__(self, device_name, description="", model="",
|
|
manufacturer="", firmware_version="", device_type="",
|
|
supported_interfaces="", companion_applications="",
|
|
save_to_file=None):
|
|
self.device_id = str(uuid.uuid4())
|
|
self.device_name = device_name
|
|
cn, aliases = make_canonical_name(device_name)
|
|
self.aliases = aliases
|
|
self.canonical_name = cn
|
|
self.date_added = datetime.now().isoformat()
|
|
self.description = description
|
|
self.model = model
|
|
self.manufacturer = manufacturer
|
|
self.current_firmware_version = firmware_version
|
|
self.device_type = device_type
|
|
self.supported_interfaces = supported_interfaces
|
|
self.companion_applications = companion_applications
|
|
self.last_metadata_update = datetime.now().isoformat()
|
|
if save_to_file is not None:
|
|
click.echo('TODO: Implement saving config to file after creation!')
|
|
|
|
def add_alias(self, alias: str = ""):
|
|
if alias == "":
|
|
return
|
|
self.aliases.append(alias)
|
|
|
|
def get_canonical_name(self):
|
|
return self.canonical_name
|
|
|
|
def print_attributes(self):
|
|
print(f'Printing attribute value pairs in {__name__}')
|
|
for attr, value in self.__dict__.items():
|
|
print(f'{attr}: {value}')
|