more changes for dictionary unpacking
This commit is contained in:
@@ -2,26 +2,28 @@ import asyncio
|
||||
import json
|
||||
|
||||
from appdaemon.adapi import ADAPI
|
||||
from appdaemon.adbase import ADBase
|
||||
from appdaemon.plugins.hass.hassapi import Hass
|
||||
|
||||
|
||||
class HelloWorld(Hass):
|
||||
class MyClass(Hass):
|
||||
def initialize(self):
|
||||
self.log('Hello World')
|
||||
# self.listen_state(
|
||||
# callback=self.temp_callback,
|
||||
# entity_id='sensor.temperature_nest',
|
||||
# attribute='state',
|
||||
# threshold=65.0,
|
||||
# )
|
||||
# self.listen_state(
|
||||
# callback=self.temp_callback,
|
||||
# entity_id='light.living_room',
|
||||
# attribute='state',
|
||||
# threshold=65.0,
|
||||
# )
|
||||
|
||||
return
|
||||
|
||||
async def temp_callback(self, entity, attribute, old, new, kwargs):
|
||||
def my_callback(self, title: str, message: str, **kwargs) -> None:
|
||||
self.log(f'{title}: {message}')
|
||||
self.log(kwargs)
|
||||
|
||||
|
||||
class HelloWorld(ADBase):
|
||||
def initialize(self):
|
||||
self.adapi = self.get_ad_api()
|
||||
|
||||
def my_callback(self, cb_args: dict) -> None:
|
||||
self.adapi.log(f'{cb_args["title"]}: {cb_args["message"]}')
|
||||
|
||||
async def temp_callback(self, entity, attribute, old, new, **kwargs):
|
||||
self.log('Temp callback')
|
||||
temp = await self.get_state('sensor.temperature_nest')
|
||||
# self.log(json.dumps(temp, indent=4))
|
||||
|
||||
@@ -97,35 +97,3 @@ class Weather(Hass):
|
||||
async def publish_temp(self, json_data):
|
||||
vals = convert_vals_dict(json_data['timelines']['hourly'][0]['values'])
|
||||
await self.set_state('weather.tomorrowio', state=vals['condition'], **vals)
|
||||
|
||||
# def create_sensor(self, name: str, **kwargs) -> None:
|
||||
# mqtt = self.app.get_plugin_api("MQTT")
|
||||
|
||||
# if "friendly_name" in kwargs:
|
||||
# friendly_name = kwargs["friendly_name"]
|
||||
# del kwargs["friendly_name"]
|
||||
# else:
|
||||
# friendly_name = name
|
||||
|
||||
# self.mqtt_registry[name] = {"entity_id": f"sensor.{name}"}
|
||||
|
||||
# if "initial_value" in kwargs:
|
||||
# # create the state topic first and set the value
|
||||
# self.set_state(name, state=kwargs["initial_value"])
|
||||
# del kwargs["initial_value"]
|
||||
|
||||
# config = {
|
||||
# "name": friendly_name,
|
||||
# "object_id": name,
|
||||
# "state_topic": f"appdaemon/{name}/state",
|
||||
# "value_template": "{{ value_json.state }}",
|
||||
# }
|
||||
|
||||
# for key, value in kwargs.items():
|
||||
# config[key] = value
|
||||
|
||||
# mqtt.mqtt_publish(
|
||||
# f"homeassistant/sensor/appdaemon/{name}/config",
|
||||
# json.dumps(config),
|
||||
# retain=True,
|
||||
# )
|
||||
|
||||
Reference in New Issue
Block a user