Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 20 additions & 18 deletions homeassistant/components/ads/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@
CONF_PORT,
EVENT_HOMEASSISTANT_STOP,
)
from homeassistant.core import HomeAssistant
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.entity import Entity
from homeassistant.helpers.typing import ConfigType

_LOGGER = logging.getLogger(__name__)

Expand Down Expand Up @@ -77,7 +79,7 @@
)


def setup(hass, config):
def setup(hass: HomeAssistant, config: ConfigType) -> bool:
"""Set up the ADS component."""

conf = config[DOMAIN]
Expand All @@ -88,23 +90,6 @@ def setup(hass, config):

client = pyads.Connection(net_id, port, ip_address)

AdsHub.ADS_TYPEMAP = {
ADSTYPE_BOOL: pyads.PLCTYPE_BOOL,
ADSTYPE_BYTE: pyads.PLCTYPE_BYTE,
ADSTYPE_DINT: pyads.PLCTYPE_DINT,
ADSTYPE_INT: pyads.PLCTYPE_INT,
ADSTYPE_UDINT: pyads.PLCTYPE_UDINT,
ADSTYPE_UINT: pyads.PLCTYPE_UINT,
}

AdsHub.ADSError = pyads.ADSError
AdsHub.PLCTYPE_BOOL = pyads.PLCTYPE_BOOL
AdsHub.PLCTYPE_BYTE = pyads.PLCTYPE_BYTE
AdsHub.PLCTYPE_DINT = pyads.PLCTYPE_DINT
AdsHub.PLCTYPE_INT = pyads.PLCTYPE_INT
AdsHub.PLCTYPE_UDINT = pyads.PLCTYPE_UDINT
AdsHub.PLCTYPE_UINT = pyads.PLCTYPE_UINT

try:
ads = AdsHub(client)
except pyads.ADSError:
Expand Down Expand Up @@ -149,6 +134,23 @@ def handle_write_data_by_name(call):
class AdsHub:
"""Representation of an ADS connection."""

ADS_TYPEMAP = {
ADSTYPE_BOOL: pyads.PLCTYPE_BOOL,
ADSTYPE_BYTE: pyads.PLCTYPE_BYTE,
ADSTYPE_DINT: pyads.PLCTYPE_DINT,
ADSTYPE_INT: pyads.PLCTYPE_INT,
ADSTYPE_UDINT: pyads.PLCTYPE_UDINT,
ADSTYPE_UINT: pyads.PLCTYPE_UINT,
}

ADSError = pyads.ADSError
PLCTYPE_BOOL = pyads.PLCTYPE_BOOL
PLCTYPE_BYTE = pyads.PLCTYPE_BYTE
PLCTYPE_DINT = pyads.PLCTYPE_DINT
PLCTYPE_INT = pyads.PLCTYPE_INT
PLCTYPE_UDINT = pyads.PLCTYPE_UDINT
PLCTYPE_UINT = pyads.PLCTYPE_UINT

Comment thread
frenck marked this conversation as resolved.
Outdated
def __init__(self, ads_client):
"""Initialize the ADS hub."""
self._client = ads_client
Expand Down
3 changes: 2 additions & 1 deletion homeassistant/components/ads/binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
BinarySensorEntity,
)
from homeassistant.const import CONF_DEVICE_CLASS, CONF_NAME
from homeassistant.core import HomeAssistant
import homeassistant.helpers.config_validation as cv

from . import CONF_ADS_VAR, DATA_ADS, STATE_KEY_STATE, AdsEntity
Expand All @@ -22,7 +23,7 @@
)


def setup_platform(hass, config, add_entities, discovery_info=None):
def setup_platform(hass: HomeAssistant, config, add_entities, discovery_info=None):
"""Set up the Binary Sensor platform for ADS."""
ads_hub = hass.data.get(DATA_ADS)

Expand Down
3 changes: 2 additions & 1 deletion homeassistant/components/ads/cover.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
CoverEntity,
)
from homeassistant.const import CONF_DEVICE_CLASS, CONF_NAME
from homeassistant.core import HomeAssistant
import homeassistant.helpers.config_validation as cv

from . import (
Expand Down Expand Up @@ -44,7 +45,7 @@
)


def setup_platform(hass, config, add_entities, discovery_info=None):
def setup_platform(hass: HomeAssistant, config, add_entities, discovery_info=None):
"""Set up the cover platform for ADS."""
ads_hub = hass.data[DATA_ADS]

Expand Down
3 changes: 2 additions & 1 deletion homeassistant/components/ads/light.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
LightEntity,
)
from homeassistant.const import CONF_NAME
from homeassistant.core import HomeAssistant
import homeassistant.helpers.config_validation as cv

from . import (
Expand All @@ -31,7 +32,7 @@
)


def setup_platform(hass, config, add_entities, discovery_info=None):
def setup_platform(hass: HomeAssistant, config, add_entities, discovery_info=None):
"""Set up the light platform for ADS."""
ads_hub = hass.data.get(DATA_ADS)

Expand Down
3 changes: 2 additions & 1 deletion homeassistant/components/ads/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from homeassistant.components import ads
from homeassistant.components.sensor import PLATFORM_SCHEMA, SensorEntity
from homeassistant.const import CONF_NAME, CONF_UNIT_OF_MEASUREMENT
from homeassistant.core import HomeAssistant
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.typing import StateType

Expand All @@ -29,7 +30,7 @@
)


def setup_platform(hass, config, add_entities, discovery_info=None):
def setup_platform(hass: HomeAssistant, config, add_entities, discovery_info=None):
"""Set up an ADS sensor device."""
ads_hub = hass.data.get(ads.DATA_ADS)

Expand Down
3 changes: 2 additions & 1 deletion homeassistant/components/ads/switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

from homeassistant.components.switch import PLATFORM_SCHEMA, SwitchEntity
from homeassistant.const import CONF_NAME
from homeassistant.core import HomeAssistant
import homeassistant.helpers.config_validation as cv

from . import CONF_ADS_VAR, DATA_ADS, STATE_KEY_STATE, AdsEntity
Expand All @@ -17,7 +18,7 @@
)


def setup_platform(hass, config, add_entities, discovery_info=None):
def setup_platform(hass: HomeAssistant, config, add_entities, discovery_info=None):
"""Set up switch platform for ADS."""
ads_hub = hass.data.get(DATA_ADS)

Expand Down