Quantcast
Channel: Configuration - Home Assistant Community
Viewing all articles
Browse latest Browse all 95919

Class objects

$
0
0

@ninjadog wrote:

Think this might be a “NO” but just checking…

Upon reading quite a few of the [dev] docs , I cannot ascertain if HA natively supports class objects, objects that can be instantiated to create a specific [derived] device based on the class object , which can then be instantiated to create a reciprocal entity.

For example, if we had10 radiator TRVs all the same model, ijmplemented on the mqtt platform as a sensor device with various entities implementing features of the device. On top of this there are scripts and automation, for each sensor which automate movement of input/output data. That’s a lot of code and maintenance for just one model of device.

Better, would be allow the user to configure a sensor class that can define public/private virtual/concrete configuration. This might be variables, automation, scripts, template etc… This would allow the user, through configuration.yaml (or include/packages) to instaniate the class and provide the required concrete attributess and overrride virtual arrtibutes.
e.g.

class:
  sensor:
    platform: "class" 
      public:
        virtual:
        #-- All required muteablevvariables of the mqtt:class_sensor component 
        #-- must be supplied here, unless they are *private* in which case
        #-- HA forces the instantiated class to provide the attribute key/value pair.
          name: string
          state_topic: string
          command_topic: string
        concrete:
        #-- These variables are available to use in instantiations
        #-- but are immuteable.
          mqtt_broker: mqtt.class_broker
      private:
        #-- These variables are not available to instantiations and are immuteable.
        #-- These would principally be mandated by the platform and would never change.
        automation:
           - alias: xyz
             // code , makes use of virtual and concrete variables //


# create component - Valid
trv:
  name: my test entity
  state_topic: "/mqtt/mytrv/state"
  command_topic: "/mqtt/mytrv/command"

# create component - INVALID
trv:
  #-- missing "name:"
  state_topic: "/mqtt/mytrv/state"
  command_topic: "/mqtt/mytrv/command"

# create component - INVALID
trv:
  #-- missing "name:"
  state_topic: "/mqtt/mytrv/state"
  command_topic: "/mqtt/mytrv/command"
  #-- attempt to override automation
  automation:

# create component - INVALID
trv:
  #-- missing "name:"
  state_topic: "/mqtt/mytrv/state"
  command_topic: "/mqtt/mytrv/command"
  #-- attempt to override mqtt_broker
  mqtt_broker: mqtt.my_broker

you get the idea?

Posts: 4

Participants: 3

Read full topic


Viewing all articles
Browse latest Browse all 95919

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>