minix1234 / hacore_opcua

opcua custom component for home assistant
MIT License
9 stars 1 forks source link

Enable SCAN_INTERVAL for entities #2

Closed minix1234 closed 3 years ago

minix1234 commented 3 years ago

the current basic sensor does not allow for setting the generic SCAN_INTERVAL settings. it appears that we should be able to pull it out from the YAML configuration and input it into the entity setup in a similar fashion to the generic sensor platform .

from datetime import timedelta

SCAN_INTERVAL = timedelta(seconds=30)

async def async_setup(hass, config):
    """Track states and offer events for sensors."""
    component = hass.data[DOMAIN] = EntityComponent(
        _LOGGER, DOMAIN, hass, SCAN_INTERVAL
    )
minix1234 commented 3 years ago

additional resources

developer documents

minix1234 commented 3 years ago

This is actually taken care of in the base structure of the sensor.py, one just needs to add a scan_interval: ## entry into the sensor definition as per below.

- platform: opcua
  scan_interval: 10
  nodes:
    - name: Sensor1
      hub: WAGO_OPC_UA
      nodeid: "ns=4;s=|var|WAGO 750-8101 PFC100 2ETH.Application.Publish_NativeMQTT.dwMyCounter"
      unit_of_measurement: degrees