JUF 4802

pydantic settings devices.juf_4802.juf_4802.Device

Show JSON schema
{
   "title": "Device",
   "type": "object",
   "properties": {
      "kind": {
         "description": "The device kind, used to load plugins",
         "title": "Kind",
         "type": "string"
      },
      "slave": {
         "description": "The Modbus slave address",
         "title": "Slave",
         "type": "integer"
      },
      "manufacturer": {
         "default": "",
         "description": "The manufacturer of the device",
         "title": "Manufacturer",
         "type": "string"
      },
      "model": {
         "default": "",
         "description": "The model of the device",
         "title": "Model",
         "type": "string"
      },
      "allow_discovery": {
         "default": true,
         "description": "Allow MQTT discovery for the device. Useful for debugging, so Eva will not publish and overwrite discovery",
         "title": "Allow Discovery",
         "type": "boolean"
      },
      "default_speed": {
         "default": 25,
         "title": "Default Speed",
         "type": "integer"
      }
   },
   "additionalProperties": true,
   "required": [
      "kind",
      "slave"
   ]
}

Config:
  • extra: str = allow

Fields:
field default_speed : --is-rst--:py:class:`int` = 25
model_post_init(_ModelMetaclass__context: Any) None

We need to both initialize private attributes and call the user-defined model_post_init method.

Return type:

None

property discovery : list[dict[str, Any]]

Provides the discovery configuration for the device

property input_config : dict[str, Any]

Builds input configuration for EvaICS to pass data from MQTT to Modbus. Please refer to MQTT input :return:

property puller_config : list[dict[str, Any]]

Builds puller configuration for EvaICS. Loads puller configuration from jinja2 template and renders it with the current object. :return:

Juf4802 device example
import DeviceConfig
from typing import List, Any, Dict
import jinja2
import yaml


class Device(DeviceConfig.DeviceConfig):
    default_speed: int = 25

    @property
    def puller_config(self) -> List[Dict[str, Any]]:
        """
        Builds puller configuration for EvaICS.
        Loads puller configuration from jinja2 template and renders it with the current object.
        :return:
        """
        import os
        env = jinja2.Environment(loader=jinja2.FileSystemLoader(os.path.dirname(__file__)),
                                 undefined=jinja2.StrictUndefined)
        t = env.get_template("puller.yml.j2").render(item=self)
        return yaml.safe_load(t)

    @property
    def input_config(self) -> Dict[str, Any]:
        """
        Builds input configuration for EvaICS to pass data from MQTT to Modbus.
        Please refer to `MQTT input
        <https://info.bma.ai/en/actual/eva4/svc/eva-controller-pubsub.html?highlight=mqtt#input>`_
        :return:
        """
        rv = {
            f"unit:{self.eva_id}/duty_perc": {
                "topic": f"{self.mqtt.base_topic}/{self.eva_id}/duty_perc/set",
                "type": "uint16",
                "reg": "h3"
            }
        }
        return rv

    @property
    def discovery(self) -> List[Dict[str, Any]]:
        rv = []
        fan = self.build_discovery(item_type="fan",
                                   payload={"device_class": "fan",
                                            "command_topic": f"{self.mqtt.base_topic}/{self.eva_id}/duty_perc",
                                            "state_value_template":
                                                "{{ 'ON' if value_json.value>0 else 'OFF' }}",
                                            "command_template":
                                                f"{{{{ 0 if value=='OFF' else "
                                                f"{self.default_speed} if value=='ON' else value }}}}",
                                            "percentage_command_topic":
                                                f"{self.mqtt.base_topic}/{self.eva_id}/duty_perc/set",
                                            "percentage_state_topic": f"{self.mqtt.base_topic}/{self.eva_id}/duty_perc",
                                            "percentage_value_template":
                                                "{{ value_json.value | is_defined }}",
                                            "state_topic": f"{self.mqtt.base_topic}/{self.eva_id}/duty_perc",
                                            "availability_topic": f"{self.mqtt.base_topic}/{self.eva_id}/duty_perc",
                                            "name": f"{self.eva_id} Fan",
                                            },
                                   slug="fan")
        rv.append(fan)
        for x in range(1, 5):
            rv.append(self.build_discovery(item_type="sensor",
                                           payload={
                                               "value_template": f"{{{{ value_json.value | is_defined }}}}",
                                               "state_class": "measurement",
                                               "unit_of_meas": "RPM",
                                               "name": f"Fan{x} RPM",
                                           },
                                           slug=f"fan{x}_rpm"))

        return rv