Skip to content

Commit

Permalink
Merge pull request #117 from grimmpp/feature-branch
Browse files Browse the repository at this point in the history
added argument to disable auto-reconnect function
  • Loading branch information
grimmpp authored Jul 1, 2024
2 parents b45aaf2 + 7edc24f commit 45418fd
Show file tree
Hide file tree
Showing 10 changed files with 28 additions and 10 deletions.
3 changes: 3 additions & 0 deletions changes.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Changes and Feature List

## Version 1.5.3 Added auto-reconnect for GWs as config parameter
* Added argument `auto_reconnect` to disable auto-reconnect for all Gateways

## Version 1.5.2 BugFix for LAN Gateway Connection
* Added argument port for LAN Gateway. Default port = 5100

Expand Down
1 change: 1 addition & 0 deletions custom_components/eltako/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
CONF_DEVICE_TYPE: Final = "device_type"
CONF_SERIAL_PATH: Final = "serial_path"
CONF_GATEWAY_ADDRESS: Final = "address"
CONF_GATEWAY_AUTO_RECONNECT: Final = "auto_reconnect"
CONF_GATEWAY_PORT: Final = "port"
CONF_CUSTOM_SERIAL_PATH: Final = "custom_serial_path"
CONF_MAX_TARGET_TEMPERATURE: Final = "max_target_temperature"
Expand Down
3 changes: 2 additions & 1 deletion custom_components/eltako/eltako_integration_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,10 @@ async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> b
gateway_name = gateway_config.get(CONF_NAME, None) # from configuration
baud_rate= BAUD_RATE_DEVICE_TYPE_MAPPING[gateway_device_type]
port = gateway_config.get(CONF_GATEWAY_PORT, 5100)
auto_reconnect = gateway_config.get(CONF_GATEWAY_AUTO_RECONNECT, True)
gateway_base_id = AddressExpression.parse(gateway_config[CONF_BASE_ID])
LOGGER.debug(f"id: {gateway_id}, device type: {gateway_device_type}, serial path: {gateway_serial_path}, baud rate: {baud_rate}, base id: {gateway_base_id}")
usb_gateway = EnOceanGateway(general_settings, hass, gateway_id, gateway_device_type, gateway_serial_path, baud_rate, port, gateway_base_id, gateway_name, config_entry)
usb_gateway = EnOceanGateway(general_settings, hass, gateway_id, gateway_device_type, gateway_serial_path, baud_rate, port, gateway_base_id, gateway_name, auto_reconnect, config_entry)

await usb_gateway.async_setup()
set_gateway_to_hass(hass, usb_gateway)
Expand Down
19 changes: 15 additions & 4 deletions custom_components/eltako/gateway.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,14 @@ class EnOceanGateway:
"""

def __init__(self, general_settings:dict, hass: HomeAssistant,
dev_id: int, dev_type: GatewayDeviceType, serial_path: str, baud_rate: int, port: int, base_id: AddressExpression, dev_name: str,
dev_id: int, dev_type: GatewayDeviceType, serial_path: str, baud_rate: int, port: int, base_id: AddressExpression, dev_name: str, auto_reconnect: bool,
config_entry: ConfigEntry):
"""Initialize the Eltako gateway."""

self._loop = asyncio.get_event_loop()
self._bus_task = None
self.baud_rate = baud_rate
self._auto_reconnect = auto_reconnect
self.port = port
self._attr_dev_type = dev_type
self._attr_serial_path = serial_path
Expand Down Expand Up @@ -127,15 +128,25 @@ def _init_bus(self):
self._fire_received_message_count_event()

if GatewayDeviceType.is_esp2_gateway(self.dev_type):
self._bus = RS485SerialInterfaceV2(self.serial_path, baud_rate=self.baud_rate, callback=self._callback_receive_message_from_serial_bus)
self._bus = RS485SerialInterfaceV2(self.serial_path,
baud_rate=self.baud_rate,
callback=self._callback_receive_message_from_serial_bus,
auto_reconnect=self._auto_reconnect)
elif GatewayDeviceType.is_lan_gateway(self.dev_type):
# lazy import to avoid preloading library
from esp2_gateway_adapter.esp3_tcp_com import TCP2SerialCommunicator
self._bus = TCP2SerialCommunicator(host=self.serial_path, port=self.port, callback=self._callback_receive_message_from_serial_bus, esp2_translation_enabled=True)
self._bus = TCP2SerialCommunicator(host=self.serial_path,
port=self.port,
callback=self._callback_receive_message_from_serial_bus,
esp2_translation_enabled=True,
auto_reconnect=self._auto_reconnect)
else:
# lazy import to avoid preloading library
from esp2_gateway_adapter.esp3_serial_com import ESP3SerialCommunicator
self._bus = ESP3SerialCommunicator(filename=self.serial_path, callback=self._callback_receive_message_from_serial_bus, esp2_translation_enabled=True)
self._bus = ESP3SerialCommunicator(filename=self.serial_path,
callback=self._callback_receive_message_from_serial_bus,
esp2_translation_enabled=True,
auto_reconnect=self._auto_reconnect)

self._bus.set_status_changed_handler(self._fire_connection_state_changed_event)

Expand Down
4 changes: 2 additions & 2 deletions custom_components/eltako/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@
"iot_class": "local_push",
"issue_tracker": "https://github.com/grimmpp/home-assistant-eltako/issues",
"loggers": ["eltako"],
"requirements": ["eltako14bus==0.0.53", "enocean==0.60.1", "StrEnum", "esp2-gateway-adapter==0.2.9"],
"version": "1.5.2"
"requirements": ["eltako14bus==0.0.53", "enocean==0.60.1", "StrEnum", "esp2-gateway-adapter==0.2.10"],
"version": "1.5.3"
}
1 change: 1 addition & 0 deletions custom_components/eltako/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,7 @@ class GatewaySchema(EltakoPlatformSchema):
vol.Required(CONF_BASE_ID): cv.matches_regex(CONF_ID_REGEX),
vol.Optional(CONF_NAME, default=""): cv.string,
vol.Optional(CONF_SERIAL_PATH): cv.string,
vol.Optional(CONF_GATEWAY_AUTO_RECONNECT, default=True): cv.boolean,
vol.Optional(CONF_GATEWAY_ADDRESS): cv.string,
vol.Optional(CONF_GATEWAY_PORT, default=5100): cv.Number,
vol.Optional(CONF_DEVICES): vol.All(vol.Schema({
Expand Down
1 change: 1 addition & 0 deletions docs/gateway_usage/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ To get familiar with the Eltako Integration configuration check out [Update Home
| `base_id` | enocean address format | Gateways can obviously receive and send messages. To send messages they use a hardcoded range of 128 addresses. The base_id is the first address of this range. Base_ids are used to identify the source of a message and to validate the configuration. |
| `devices` | configuration | Devices grouped by Home Assistant platform types. All devices which are listed here will be represented by this device. Device listed more than one in different devices will be recognized as two independent devices. |
| `serial_path` | optional string | for serial paths which won't be auto detected. Can be also used for serial over tcp. |
| `auto_reconnect` | True / False | for disabling auto-reconnect function. If not specified: True |
| `address` | IPv4 or IPv6 | only required for TCP/LAN gateway |
| `port` | Number | only used for TCP/LAN gateway. If not specified: 5100 |

Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ enocean==0.60.1
homeassistant
termcolor
StrEnum
esp2-gateway-adapter==0.2.9
esp2-gateway-adapter==0.2.10
2 changes: 1 addition & 1 deletion tests/mocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def __init__(self, general_settings:dict=DEFAULT_GENERAL_SETTINGS, dev_id: int=1
hass = HassMock()
gw_type = GatewayDeviceType.GatewayEltakoFAM14

super().__init__(general_settings, hass, dev_id, gw_type, 'SERIAL_PATH', 56700, 5100, base_id, "MyFAM14", ConfigEntryMock())
super().__init__(general_settings, hass, dev_id, gw_type, 'SERIAL_PATH', 56700, 5100, base_id, "MyFAM14", auto_reconnect=True, config_entry=ConfigEntryMock())

self._bus = EltakoBusMock()

Expand Down
2 changes: 1 addition & 1 deletion tests/test_gateway.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def test_gateway_creation(self):
baud_rate = BAUD_RATE_DEVICE_TYPE_MAPPING[sub_type]
conf = ConfigEntry(version=1, minor_version=0, domain=DOMAIN, title="gateway", data={}, source=None, options=None, unique_id=None)
gw = EnOceanGateway(DEFAULT_GENERAL_SETTINGS, HassMock(),
dev_id=123, dev_type=sub_type, serial_path="serial_path", baud_rate=baud_rate, port=None, base_id=AddressExpression.parse('FF-AA-00-00'), dev_name="GW",
dev_id=123, dev_type=sub_type, serial_path="serial_path", baud_rate=baud_rate, port=None, base_id=AddressExpression.parse('FF-AA-00-00'), dev_name="GW", auto_reconnect=True,
config_entry=conf)

self.assertEqual(gw.identifier, basename(normpath('serial_path')))
Expand Down

0 comments on commit 45418fd

Please sign in to comment.