Skip to content

Commit

Permalink
fixed lan gateway connection
Browse files Browse the repository at this point in the history
  • Loading branch information
grimmpp committed Jun 25, 2024
1 parent 708e113 commit 1d57803
Show file tree
Hide file tree
Showing 11 changed files with 22 additions and 8 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.2 BugFix for LAN Gateway Connection
* Added argument port for LAN Gateway. Default port = 5100

## Version 1.5.1 Added into HACS list
* Added Eltako Intgration into list of HACS

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_PORT: Final = "port"
CONF_CUSTOM_SERIAL_PATH: Final = "custom_serial_path"
CONF_MAX_TARGET_TEMPERATURE: Final = "max_target_temperature"
CONF_MIN_TARGET_TEMPERATURE: Final = "min_target_temperature"
Expand Down
7 changes: 6 additions & 1 deletion custom_components/eltako/eltako_integration_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,14 +124,19 @@ async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> b
if gateway_device_type is None:
LOGGER.error(f"[{LOG_PREFIX}] USB device {gateway_config[CONF_DEVICE_TYPE]} is not supported!!!")
return False
if gateway_device_type == GatewayDeviceType.LAN:
if gateway_config.get(CONF_GATEWAY_ADDRESS, None) is None:
raise Exception(f"Missing field '{CONF_GATEWAY_ADDRESS}' for LAN Gateway (id: {gateway_id})")

general_settings[CONF_ENABLE_TEACH_IN_BUTTONS] = True # GatewayDeviceType.is_transceiver(gateway_device_type) # should only be disabled for decentral gateways

LOGGER.info(f"[{LOG_PREFIX}] Initializes Gateway Device '{gateway_description}'")
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)
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, 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, config_entry)

await usb_gateway.async_setup()
set_gateway_to_hass(hass, usb_gateway)
Expand Down
6 changes: 4 additions & 2 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, 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,
config_entry: ConfigEntry):
"""Initialize the Eltako gateway."""

self._loop = asyncio.get_event_loop()
self._bus_task = None
self.baud_rate = baud_rate
self.port = port
self._attr_dev_type = dev_type
self._attr_serial_path = serial_path
self._attr_identifier = basename(normpath(serial_path))
Expand Down Expand Up @@ -128,8 +129,9 @@ def _init_bus(self):
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)
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=5100, 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)
else:
# lazy import to avoid preloading library
from esp2_gateway_adapter.esp3_serial_com import ESP3SerialCommunicator
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.6"],
"version": "1.5.1"
"requirements": ["eltako14bus==0.0.53", "enocean==0.60.1", "StrEnum", "esp2-gateway-adapter==0.2.9"],
"version": "1.5.2"
}
1 change: 1 addition & 0 deletions custom_components/eltako/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,7 @@ class GatewaySchema(EltakoPlatformSchema):
vol.Optional(CONF_NAME, default=""): cv.string,
vol.Optional(CONF_SERIAL_PATH): cv.string,
vol.Optional(CONF_GATEWAY_ADDRESS): cv.string,
vol.Optional(CONF_GATEWAY_PORT, default=5100): cv.Number,
vol.Optional(CONF_DEVICES): vol.All(vol.Schema({
**BinarySensorSchema.platform_node(),
**LightSchema.platform_node(),
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 @@ -19,6 +19,7 @@ To get familiar with the Eltako Integration configuration check out [Update Home
| `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. |
| `address` | IPv4 or IPv6 | only required for TCP/LAN gateway |
| `port` | Number | only used for TCP/LAN gateway. If not specified: 5100 |


### Example Configuration
Expand Down
1 change: 1 addition & 0 deletions docs/gateways/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,7 @@ eltako:
device_type: mgw-lan
base_id: FF-80-80-00 # baseId of LAN gateway
address: 192.168.178.15 # address is only required for LAN gateway
port: 5100 # optional (default value 5100). Field only valid for LAN gateway
devices:
light:
- id: FF-AA-00-01 # baseId of FAM14 (FF-AA-00-00) + internal address
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.6
esp2-gateway-adapter==0.2.9
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, base_id, "MyFAM14", ConfigEntryMock())
super().__init__(general_settings, hass, dev_id, gw_type, 'SERIAL_PATH', 56700, 5100, base_id, "MyFAM14", 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)
gw = EnOceanGateway(DEFAULT_GENERAL_SETTINGS, HassMock(),
dev_id=123, dev_type=sub_type, serial_path="serial_path", baud_rate=baud_rate, 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",
config_entry=conf)

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

0 comments on commit 1d57803

Please sign in to comment.