Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_instantiation():
spine = MockupSpine()
component = KerviComponent("test_component", "component", "Test component", spine=spine)
assert component.component_id == "test_component"
assert component.component_type == "component"
assert component.name == "Test component"
assert component.visible
assert "getDashboardComponents" in spine.queryHandlers
assert "getComponentInfo" in spine.queryHandlers
* **flat** (``bool``) -- Flat look and feel.
* **inline** (``bool``) -- Display value, sparkline and label in its actual size otherwise it occupys the entire with of the panel
* **type** (``str``) -- One of the following values *radial_gauge*, *vertical_gauge*, *horizontal_gauge*, *chart* or *value*.
* **show_sparkline** (``bool``) -- Show a sparkline next to the value.
* **icon** (``bool``) -- Icon to show. All Font Awesome icons are valid just enter the name of the icon without *fa-*.
* **show_value** (``bool``) -- Show the numeric value and unit.
* **label** (``str``) -- Label to show default is the name of the sensor.
"""
KerviComponent.link_to_dashboard(self, dashboard_id, panel_id, **kwargs)
* *label_icon* (``str``) -- Icon that should be displayed together with label.
* *label* (``str``) -- Label text, default value is the name of the DynamicValue.
* *flat* (``bool``) -- Flat look and feel.
* *inline* (``bool``) -- Display DynamicValue and label in its actual size
If you set inline to true the size parameter is ignored.
The DynamicValue will only occupy as much space as the label and input takes.
* *input_size* (``int``) -- width of the slider as a percentage of the total container it sits in.
* *value_size* (``int``) -- width of the value area as a percentage of the total container it sits in.
"""
KerviComponent.link_to_dashboard(
self,
dashboard_id,
section_id,
**kwargs
)
def run(self):
self.result = self._action._execute(*self._args, **self._kwargs)
class _ActionInterupt():
def __init__(self, interupt):
self._interupt = interupt
argspec = inspect.getargspec(interupt)
self._keywords = argspec.keywords != None
def __call__(self, *args, **kwargs):
if self._keywords:
self._interupt(*args, **kwargs)
else:
self._interupt(*args)
class Action(KerviComponent):
"""The Action class is used by the action decorator. A function or method that is marked with @actions os converted to an Action class"""
def __init__(self, handler, action_id, name=None):
super().__init__(action_id, "KerviAction", name)
self.action_id = action_id
self._handler = handler
argspec = inspect.getargspec(handler)
self._keywords = argspec.keywords != None
#print("kw", self.action_id, self._keywords, argspec, handler)
self.spine = Spine()
self.spine.register_command_handler("kervi_action_" + action_id, self._handle_command)
self.spine.register_command_handler("kervi_action_interupt_" + action_id, self.interupt)
self._state = ACTION_STOPPED
self._action_lock = threading.Lock()
self._last_result = None
self._is_running = False
self._interupt = None
* *on_text* (``string``) -- Text to display when switch is on.
* *off_text* (``string``) -- Text to display when switch is off.
* *on_icon* (``string``) -- Icon to display when switch is on.
* *off_icon* (``string``) -- Icon to display when switch is off.
* *button_icon* (``string``) -- Icon to display on button.
* *button_text* (``string``) -- Text to display on button, default is name.
* *action_parameters* (``list``) -- List of parameters to pass to the action.
* *interupt_enabled* (``bool``) -- If true the button will send interupt to action on off. Default true if an interupt is specified for the action.
* *interupt_parameters* (``list``) -- List of parameters to pass to the interupt function of the action.
"""
KerviComponent.link_to_dashboard(
self,
dashboard_id,
section_id,
**kwargs
)
def __init__(self, sensor_id, name, device=None, use_thread=True):
KerviComponent.__init__(self, sensor_id, "sensor", name)
self._device = device
self._type = None
self._max = None
self._min = None
self._unit = None
if self._device:
self._type = self._device.type
self._unit = self._device.unit
self._min = self._device.min
self._max = self._device.max
self._upper_fatal_limit = None
self._upper_warning_limit = None
self._lower_warning_limit = None
def __init__(self, name, value_type, **kwargs):
global VALUE_COUNTER
parent = kwargs.get("parent", None)
input_id = kwargs.get("value_id", None)
if input_id is None:
VALUE_COUNTER += 1
if parent:
input_id = parent.component_id + ".VALUE_" + str(VALUE_COUNTER)
else:
input_id = "VALUE_" + str(VALUE_COUNTER)
elif parent:
input_id = parent.component_id + "." + input_id
KerviComponent.__init__(self, input_id, value_type, name, **kwargs)
#self.spine = Spine()
self._unit = ""
self._default_value = None
self._index = kwargs.get("index", None)
self.is_input = kwargs.get("is_input", True)
self._value = None
self._sparkline = []
self._observers = []
self._value_event_handlers = []
if parent:
self._observers += [parent]
self._spine_observers = {}
self.command = self.component_id + ".setValue"
self.spine.register_command_handler(self.command, self._set_value, groups=self.admin_groups)
self.spine.register_query_handler("getKerviValue", self._query_value, groups=self.user_groups)
if authorized:
components = self.spine.send_query(
"getDashboardComponents",
self.dashboard.dashboard_id,
self.panel_id
)
panel_components = self._get_panel_components(components)
return {
"id": self.panel_id,
"type": "panel",
"uiParameters": self.ui_parameters,
"dashboard": self.dashboard.get_reference(),
"components": panel_components
}
class Dashboard(KerviComponent):
r"""
Create a UI dashboard. The dashboard will show up in the dashboard menu in the UI.
A dashboard contains one or more panels. Kervi components like *sensors*,
*controller inputs* and other dynamic values are able to link to a panel on a dashboard.
All dashboard have the following system defined panels:
* header_right
* header_center
* footer_left
* footer_center
* footer_right
Besides from these panels each dashboard has two *controller pad* areas where
it is possible to link to the x and y coordinates of the pads.
A dynamic value like controller input may link to one of the following panels:
components = self.spine.send_query(
"getDashboardComponents",
self.dashboard.dashboard_id,
self.panel_id
)
panel_components = self._get_panel_components(components)
return {
"id": self.panel_id,
"type": "panel",
"uiParameters": self.ui_parameters,
"dashboard": self.dashboard.get_reference(),
"components": panel_components
}
class Dashboard(KerviComponent):
r"""
Create a UI dashboard. The dashboard will show up in the dashboard menu in the UI.
A dashboard contains one or more panels. Kervi components like *sensors*,
*controller inputs* and other dynamic values are able to link to a panel on a dashboard.
All dashboard have the following system defined panels:
* header_right
* header_center
* footer_left
* footer_center
* footer_right
Besides from these panels each dashboard has two *controller pad* areas where
it is possible to link to the x and y coordinates of the pads.
A dynamic value like controller input may link to one of the following panels:
def __init__(self, dashboard_id, name, panels=None, **kwargs):
KerviComponent.__init__(self, dashboard_id, "dashboard", name)
self.dashboard_id = dashboard_id
self.is_default = kwargs.get("is_default", False)
self.gauge_width = kwargs.get("gauge_width", 0)
self.gauge_height = kwargs.get("gauge_height", 0)
self.panel_width = kwargs.get("panel_width", 0),
self.panel_height = kwargs.get("panel_height", 0),
self.panels = []
self.add_panel(DashboardPanel("header_right"))
self.add_panel(DashboardPanel("header_center"))
self.add_panel(DashboardPanel("footer_center"))
self.add_panel(DashboardPanel("footer_left"))
self.add_panel(DashboardPanel("footer_right"))
self.add_panel(DashboardPanel("background"))
self.add_panel(DashboardPanel("left_pad_x"))
self.add_panel(DashboardPanel("left_pad_y"))
self.add_panel(DashboardPanel("right_pad_x"))