From 42dd2d517ff170685f84a615f15697389af20ea5 Mon Sep 17 00:00:00 2001 From: Pergola Fabio Date: Wed, 26 Jul 2023 13:12:38 +0200 Subject: [PATCH] Add dynamic ports for 8000 and 1883 --- hikvision-doorbell/config.yaml | 1 + hikvision-doorbell/default_config.yaml | 3 ++- hikvision-doorbell/development.env.example | 4 +++- hikvision-doorbell/docs/docker.md | 3 ++- hikvision-doorbell/src/config.py | 3 ++- hikvision-doorbell/src/doorbell.py | 2 +- hikvision-doorbell/src/mqtt.py | 1 + 7 files changed, 12 insertions(+), 5 deletions(-) diff --git a/hikvision-doorbell/config.yaml b/hikvision-doorbell/config.yaml index 31c8a6e..1cf29aa 100644 --- a/hikvision-doorbell/config.yaml +++ b/hikvision-doorbell/config.yaml @@ -29,6 +29,7 @@ schema: doorbells: - name: str ip: str + port: "int?" username: str password: str output_relays: "int?" diff --git a/hikvision-doorbell/default_config.yaml b/hikvision-doorbell/default_config.yaml index 0cb310d..ad18b5e 100644 --- a/hikvision-doorbell/default_config.yaml +++ b/hikvision-doorbell/default_config.yaml @@ -9,6 +9,7 @@ doorbells: [] # Uncomment the following lines and define each doorbell by repeating the example config: # - name: "Front porch" # ip: 192.168.0.1 +# port: 8000 # username: admin # password: password @@ -20,8 +21,8 @@ doorbells: [] # Define the following options to enable the MQTT integration # mqtt: # host: localhost -# port: 1883 # # Optionals settings: +# port: 1883 # ssl: # Set to true to enable SSL # username: # password: diff --git a/hikvision-doorbell/development.env.example b/hikvision-doorbell/development.env.example index 3ee497b..e06e947 100644 --- a/hikvision-doorbell/development.env.example +++ b/hikvision-doorbell/development.env.example @@ -1,7 +1,8 @@ # Example .env files for local development. Make a copy of it and set your own parameters # JSON-encoded string containing the list of doorbells to connect to -DOORBELLS=[{"name":"outdoor", "ip": "192.168.0.1", "username": "user", "password": "password"}] + +DOORBELLS=[{"name":"outdoor", "ip": "192.168.0.1", "port": 8000, "username": "user", "password": "password"}] # Connection to Home Assistant API (deprecated, use MQTT instead) # HOME_ASSISTANT__URL=http://localhost:8123 @@ -10,6 +11,7 @@ DOORBELLS=[{"name":"outdoor", "ip": "192.168.0.1", "username": "user", "password # Connection to MQTT broker MQTT__HOST=localhost # Optionals: +MQTT__PORT=1883 MQTT__USERNAME= MQTT__PASSWORD= diff --git a/hikvision-doorbell/docs/docker.md b/hikvision-doorbell/docs/docker.md index d6994fd..4f3c868 100644 --- a/hikvision-doorbell/docs/docker.md +++ b/hikvision-doorbell/docs/docker.md @@ -16,11 +16,12 @@ services: tty: true # To receive commands on STDIN env: # JSON string with the list of doorbells - DOORBELLS: '[{"name":"outdoor", "ip": "192.168.0.1", "username": "user", "password": "password"}]' + DOORBELLS: '[{"name":"outdoor", "ip": "192.168.0.1", "port": 8000, "username": "user", "password": "password"}]' # Connection to the MQTT broker MQTT__HOST: # Optionals + MQTT__PORT: 1883 MQTT__USERNAME: MQTT__PASSWORD: diff --git a/hikvision-doorbell/src/config.py b/hikvision-doorbell/src/config.py index 67d53c8..caf4a51 100644 --- a/hikvision-doorbell/src/config.py +++ b/hikvision-doorbell/src/config.py @@ -67,6 +67,7 @@ class AppConfig(GoodConf): class Doorbell(BaseModel): name: str = Field(description="Custom name of the doorbell") ip: str + port: Optional[int] = 8000 username: str password: str output_relays: Optional[int] = None # TODO: validate it is in acceppable range! @@ -86,7 +87,7 @@ def check_url_path(cls, v): class MQTT(BaseModel): host: str - port: int = 1883 + port: Optional[int] = 1883 ssl: Optional[bool] = Field(default=False, description="Set to true to enable SSL") username: Optional[str] = None password: Optional[str] = None diff --git a/hikvision-doorbell/src/doorbell.py b/hikvision-doorbell/src/doorbell.py index 2a59d19..53a119a 100644 --- a/hikvision-doorbell/src/doorbell.py +++ b/hikvision-doorbell/src/doorbell.py @@ -51,7 +51,7 @@ def authenticate(self): self._device_info = NET_DVR_DEVICEINFO_V30() self.user_id = self._sdk.NET_DVR_Login_V30( bytes(self._config.ip, 'utf8'), - 8000, + self._config.port, bytes(self._config.username, 'utf8'), bytes(self._config.password, 'utf8'), self._device_info diff --git a/hikvision-doorbell/src/mqtt.py b/hikvision-doorbell/src/mqtt.py index 205198e..a381efc 100644 --- a/hikvision-doorbell/src/mqtt.py +++ b/hikvision-doorbell/src/mqtt.py @@ -93,6 +93,7 @@ def __init__(self, config: AppConfig.MQTT, doorbells: Registry) -> None: # Save the MQTT settings as an attribute self._mqtt_settings = Settings.MQTT( host=config.host, + port=config.port, username=config.username, password=config.password )