Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Skeleton of Discovery Implementation #381

Merged
merged 5 commits into from
Apr 14, 2021

Conversation

krkeegan
Copy link
Collaborator

Proposed change

This is a functioning basic implementation of the Discovery feature. It lacks lots of documentation, and is only implemented on Dimmers. The idea is this:

  1. There are some global yaml settings for discovery such as discovery_topic_base and discovery_ha_status
  2. There is a global setting for device_info_template that allows the user to define a device template that can be reused as a variable in the discovery templates. @schirner had implemented something like this, and I agree this is very handy. This is likely to be reused in every template.
  3. By default each device class will look in it's subkey under the mqtt key in the config.yaml file for the discovery templates. So dimmers look to mqtt->dimmer by default.
  4. Inside this class, a discovery_entities key is defined. This key must have a component subkey and config key. The config key must include at minimum a unique_id. Other HomeAssistant config settings also need to be defined.
  5. The templates have a lot of variables available to them including: name, address, name_user_case, engine, model, firmware, modem_addr, device_info_template. Additionally all topics defined in yaml are also available.
  6. The discovery topics are automatically generated, I don't see any reason why a user would need to edit these, they do not have any effect on how HomeAssistant functions.

Customization

As referenced in the min_hops addition, users can create new discovery classes that can be used on one or more devices. By specifying discovery_class as an config_extra key for the device. The value is a reference to a key under the mqtt section. This new subkey would then need to contain a discovery_entities key as defined above.

Additional information

Checklist

  • The code change is tested and works locally.
  • Local tests pass. Your PR cannot be merged unless tests pass
  • Tests have been added to verify that the new code works.
  • Code documentation was added where necessary
  • Documentation added/updated

Below is a sample of the published topic homeassistant/light/4f.23.38/4f.23.38_light/config using the config settings shown in the attached commits:

{
  "uniq_id": "4f.23.38_light",
  "name": "dimmer",
  "cmd_t": "insteon/4f.23.38/level",
  "stat_t": "insteon/4f.23.38/state",
  "brightness": true,
  "schema": "json",
  "device": {
  "ids": "4f.23.38",
  "mf": "Insteon",
  "mdl": "DIMMABLE_LIGHTING (0x01): '2477D' (0x20) 'SwitchLinc Dimmer (Dual-Band)'",
  "sw": "69",
  "name": "dimmer",
  "via_device": "41.ee.e6"
}
}

Adds the basic functionality for reading discovery settings from
the config.yaml file.  Lightly implemented in Dimmer.

Still does not publish anything yet, need to monitor the
homeassistant/status topic
Monitors a defined topic looking for a message indicating that
HomeAssistant was restarted and triggers a re-publish of
discovery entities if that happens.

Publish discovery entities on startup.
Device information is likely to be the same structure across all
devices.  Or at least most devices.  This adds a variable that
is defined in yaml and useable in the jinja templates.

Add basic dimmer discovery entities.
@krkeegan
Copy link
Collaborator Author

Oh, I should note, the current design publishes all discovery entities when IM starts up and republishes them anytime it see HA restart. It seems to be working fine.

@krkeegan krkeegan merged commit 4b5822d into TD22057:Discovery Apr 14, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant