Move main config to config.toml
This commit is contained in:
parent
477cc99247
commit
119feee5e5
3 changed files with 42 additions and 12 deletions
|
@ -14,18 +14,20 @@ class HAClient:
|
|||
self,
|
||||
entity: str,
|
||||
secondary_entities: list[str] = [],
|
||||
config: dict = dict(),
|
||||
mqtt_config: dict = dict(),
|
||||
) -> None:
|
||||
self.entity = entity
|
||||
self.secondary_entities = secondary_entities
|
||||
self.config = config
|
||||
self.config = mqtt_config
|
||||
|
||||
self.state_topic = "oin/state"
|
||||
self.availability_topic = "oin/availability"
|
||||
|
||||
self.client = mqtt.Client(mqtt.CallbackAPIVersion.VERSION2)
|
||||
username = self.config.get("username", None)
|
||||
logger.debug(f"Setting up MQTT with user <{username}>")
|
||||
self.client.username_pw_set(
|
||||
username=self.config.get("username", None),
|
||||
username=username,
|
||||
password=self.config.get("password", None),
|
||||
)
|
||||
|
||||
|
@ -48,9 +50,12 @@ class HAClient:
|
|||
}
|
||||
|
||||
def connect(self) -> None:
|
||||
logger.debug("Connecting to HA...")
|
||||
self.client.will_set(self.availability_topic, "offline", retain=True)
|
||||
self.client.connect(self.config.get("host"), self.config.get("port", 1883))
|
||||
|
||||
host = self.config.get("host")
|
||||
port = self.config.get("port", 1883)
|
||||
logger.debug(f"Connecting to <{host}> on port <{port}>")
|
||||
self.client.connect(host, port)
|
||||
|
||||
self.subscribe(entity_topic(self.entity), self.state_update)
|
||||
for entity in self.secondary_entities:
|
||||
|
|
Reference in a new issue