Skip to content

Commit

Permalink
Merge pull request #123 from pergolafabio/feat/dynamic_ports
Browse files Browse the repository at this point in the history
Add dynamic ports for 8000
  • Loading branch information
pergolafabio authored Jul 26, 2023
2 parents 3ae3746 + 42dd2d5 commit 425602f
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 5 deletions.
1 change: 1 addition & 0 deletions hikvision-doorbell/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ schema:
doorbells:
- name: str
ip: str
port: "int?"
username: str
password: str
output_relays: "int?"
Expand Down
3 changes: 2 additions & 1 deletion hikvision-doorbell/default_config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -20,8 +21,8 @@ doorbells: []
# Define the following options to enable the MQTT integration
# mqtt:
# host: localhost
# port: 1883
# # Optionals settings:
# port: 1883
# ssl: <boolean> # Set to true to enable SSL
# username: <user>
# password: <password>
Expand Down
4 changes: 3 additions & 1 deletion hikvision-doorbell/development.env.example
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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=<username>
MQTT__PASSWORD=<password>

Expand Down
3 changes: 2 additions & 1 deletion hikvision-doorbell/docs/docker.md
Original file line number Diff line number Diff line change
Expand Up @@ -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: <hostname_of_broker>
# Optionals
MQTT__PORT: 1883
MQTT__USERNAME: <broker_username>
MQTT__PASSWORD: <broker_password>

Expand Down
3 changes: 2 additions & 1 deletion hikvision-doorbell/src/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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!
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion hikvision-doorbell/src/doorbell.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions hikvision-doorbell/src/mqtt.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down

0 comments on commit 425602f

Please sign in to comment.