ESBO-ETC/esbo_etc/classes/sensor/SensorFactory.py

50 lines
1.5 KiB
Python
Raw Normal View History

2020-09-10 15:03:57 +02:00
from ..AFactory import AFactory
2020-05-13 14:33:22 +02:00
from ..IRadiant import IRadiant
from ..Entry import Entry
from .ASensor import ASensor
2020-09-12 11:51:49 +02:00
from ...classes import sensor as sensor
2020-05-29 09:36:02 +02:00
from ...lib.logger import logger
2020-05-13 14:33:22 +02:00
2020-09-10 15:03:57 +02:00
class SensorFactory(AFactory):
2020-05-13 14:33:22 +02:00
"""
A Factory creating objects of the type ASensor
"""
2020-09-10 15:03:57 +02:00
def __init__(self, common_conf: Entry):
2020-05-13 14:33:22 +02:00
"""
Instantiate a new factory object
2020-09-10 15:03:57 +02:00
Parameters
----------
common_conf : Entry
The common configuration of the configuration file
2020-05-13 14:33:22 +02:00
"""
2020-09-10 15:03:57 +02:00
super().__init__(common_conf)
2020-05-13 14:33:22 +02:00
2020-09-10 15:31:07 +02:00
def create(self, options: Entry, parent: IRadiant = None) -> ASensor:
2020-05-13 14:33:22 +02:00
"""
2020-09-10 15:03:57 +02:00
Create a new sensor object
2020-05-13 14:33:22 +02:00
Parameters
----------
options : Entry
The options to be used as parameters for the instantiation of the new object.
2020-09-10 15:03:57 +02:00
parent : IRadiant
The parent element of the object.
2020-05-13 14:33:22 +02:00
Returns
-------
obj : ASensor
The created sensor object
"""
2020-09-12 11:51:49 +02:00
if parent is not None:
opts = self.collectOptions(options)
2020-09-10 15:03:57 +02:00
args = dict(parent=parent, **opts, common_conf=self._common_conf)
2020-09-12 11:51:49 +02:00
if hasattr(sensor, options.type):
class_ = getattr(sensor, options.type)
return class_(**args)
else:
logger.error("Unknown sensor type: '" + options.type + "'")
2020-05-13 14:33:22 +02:00
else:
2020-09-12 11:51:49 +02:00
logger.error("Parent object is required for sensor.")