Skip to content

Commit 38c5cbf

Browse files
committed
fix ha_url fix attributes
1 parent a1f56a2 commit 38c5cbf

1 file changed

Lines changed: 36 additions & 44 deletions

File tree

apps/elco-remocon-net-appdaemon/elco-remocon-net-appdaemon.py

Lines changed: 36 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -17,136 +17,133 @@ def post_to_entities(self, data):
1717
self.log("Posting to entities...")
1818

1919
def _post_data(sensor, payload):
20-
entity_url = f"{ha_url}/api/states/{sensor}"
21-
token = "Bearer {}".format(self.args["bearer_token"])
22-
headers = {"Authorization": token, "Content-Type": "application/json"}
2320
try:
21+
# elco_sensor = self.get_entity(sensor)
22+
# if elco_sensor is None:
23+
entity_url = f"{ha_url}/api/states/{sensor}"
24+
token = "Bearer {}".format(self.args["bearer_token"])
25+
headers = {"Authorization": token, "Content-Type": "application/json"}
2426
result = requests.post(entity_url, json=payload, headers=headers)
25-
self.log(f"POST'ed {sensor} to {entity_url}")
27+
self.log(f"Set state on entity {sensor}")
28+
# else:
29+
# elco_sensor.set_state(state = payload["state"], attributes = payload["attributes"])
30+
# self.log(f"update state of {sensor}")
31+
2632
except Exception as e:
2733
self.log(e)
2834

2935
def _post_plantData(plantData):
3036
elco_outside_temperature = {
31-
"unique_id": "elco_outside_temperature",
3237
"state": plantData["outsideTemp"],
3338
"attributes": {
3439
"unit_of_measurement": "°C",
3540
"device_class": "temperature",
41+
"friendly_name": "Elco Outside Temperature",
3642
},
37-
"friendly_name": "Elco Outside Temperature",
3843
}
3944
_post_data("sensor.elco_outside_temperature", elco_outside_temperature)
4045

4146
elco_domestic_hot_water_storage_temperature = {
42-
"unique_id": "elco_domestic_hot_water_storage_temperature",
4347
"state": plantData["dhwStorageTemp"],
4448
"attributes": {
4549
"unit_of_measurement": "°C",
4650
"device_class": "temperature",
51+
"friendly_name": "Elco Domestic Hot Water Storage Temperature",
4752
},
48-
"friendly_name": "Elco Domestic Hot Water Storage Temperature",
4953
}
5054
_post_data(
5155
"sensor.elco_domestic_hot_water_storage_temperature",
5256
elco_domestic_hot_water_storage_temperature,
5357
)
5458

5559
elco_domestic_hot_water_temperature = {
56-
"unique_id": "elco_domestic_hot_water_temperature",
5760
"state": plantData["dhwComfortTemp"]["value"],
5861
"attributes": {
5962
"unit_of_measurement": "°C",
6063
"device_class": "temperature",
6164
"min": plantData["dhwComfortTemp"]["min"],
6265
"max": plantData["dhwComfortTemp"]["max"],
6366
"step": plantData["dhwComfortTemp"]["step"],
67+
"friendly_name": "Elco Domestic Hot Water Storage Temperature",
6468
},
65-
"friendly_name": "Elco Domestic Hot Water Storage Temperature",
6669
}
6770
_post_data(
6871
"sensor.elco_domestic_hot_water_temperature",
6972
elco_domestic_hot_water_temperature,
7073
)
7174

7275
elco_domestic_hot_water_reduced_temperature = {
73-
"unique_id": "elco_domestic_hot_water_reduced_temperature",
7476
"state": plantData["dhwReducedTemp"]["value"],
7577
"attributes": {
7678
"unit_of_measurement": "°C",
7779
"device_class": "temperature",
7880
"min": plantData["dhwReducedTemp"]["min"],
7981
"max": plantData["dhwReducedTemp"]["max"],
8082
"step": plantData["dhwReducedTemp"]["step"],
83+
"friendly_name": "Elco Domestic Hot Water Storage Reduced Temperature",
8184
},
82-
"friendly_name": "Elco Domestic Hot Water Storage Reduced Temperature",
8385
}
8486
_post_data(
8587
"sensor.elco_domestic_hot_water_reduced_temperature",
8688
elco_domestic_hot_water_reduced_temperature,
8789
)
8890

8991
elco_domestic_hot_water_storage_mode = {
90-
"unique_id": "elco_domestic_hot_water_storage_mode",
9192
"state": "on" if plantData["dhwMode"]["value"] == 1 else "off",
9293
"attributes": {
9394
"device_class": "running",
95+
"friendly_name": "Elco Domestic Hot Water Storage Mode",
96+
"icon": "mdi:hvac",
9497
},
95-
"icon": "mdi:hvac",
96-
"friendly_name": "Elco Domestic Hot Water Storage Mode",
9798
}
9899
_post_data(
99100
"binary_sensor.elco_domestic_hot_water_storage_mode",
100101
elco_domestic_hot_water_storage_mode,
101102
)
102103

103104
elco_domestic_hot_water_storage_temperature_error = {
104-
"unique_id": "elco_domestic_hot_water_storage_temperature_error",
105105
"state": "on" if plantData["dhwStorageTempError"] == 1 else "off",
106106
"attributes": {
107107
"device_class": "problem",
108+
"icon": "mdi:radiator",
109+
"friendly_name": "Elco Domestic Hot Water Storage Temperature Error",
108110
},
109-
"icon": "mdi:radiator",
110-
"friendly_name": "Elco Domestic Hot Water Storage Temperature Error",
111111
}
112112
_post_data(
113113
"binary_sensor.elco_domestic_hot_water_storage_temperature_error",
114114
elco_domestic_hot_water_storage_temperature_error,
115115
)
116116

117117
elco_outside_temperature_error = {
118-
"unique_id": "elco_outside_temperature_error",
119118
"state": "on" if plantData["outsideTempError"] == 1 else "off",
120119
"attributes": {
121120
"device_class": "problem",
121+
"icon": "mdi:radiator",
122+
"friendly_name": "Elco Outside Temperature Error",
122123
},
123-
"icon": "mdi:radiator",
124-
"friendly_name": "Elco Outside Temperature Error",
125124
}
126125
_post_data(
127126
"binary_sensor.elco_outside_temperature_error",
128127
elco_outside_temperature_error,
129128
)
130129

131130
elco_heatpump_on = {
132-
"unique_id": "elco_heatpump_on",
133131
"state": "on" if plantData["heatPumpOn"] == 1 else "off",
134132
"attributes": {
135133
"device_class": "running",
134+
"icon": "mdi:radiator",
135+
"friendly_name": "Elco HeatPump On",
136136
},
137-
"icon": "mdi:radiator",
138-
"friendly_name": "Elco HeatPump On",
139137
}
140138
_post_data("binary_sensor.elco_heatpump_on", elco_heatpump_on)
141139

142140
elco_domestic_hot_water_enabled = {
143-
"unique_id": "elco_domestic_hot_water_enabled",
144141
"state": "on" if plantData["dhwEnabled"] == 1 else "off",
145142
"attributes": {
146143
"device_class": "running",
144+
"icon": "mdi:radiator",
145+
"friendly_name": "Elco Domestic Hot Water Enabled",
147146
},
148-
"icon": "mdi:radiator",
149-
"friendly_name": "Elco Domestic Hot Water Enabled",
150147
}
151148
_post_data(
152149
"binary_sensor.elco_domestic_hot_water_enabled",
@@ -155,107 +152,102 @@ def _post_plantData(plantData):
155152

156153
def _post_zoneData(zoneData):
157154
elco_comfort_room_temperature_setpoint = {
158-
"unique_id": "elco_comfort_room_temperature_setpoint",
159155
"state": zoneData["chComfortTemp"]["value"],
160156
"attributes": {
161157
"unit_of_measurement": "°C",
162158
"device_class": "temperature",
163159
"min": zoneData["chComfortTemp"]["min"],
164160
"max": zoneData["chComfortTemp"]["max"],
165161
"step": zoneData["chComfortTemp"]["step"],
162+
"friendly_name": "Elco Comfort room Temperature setpoint",
166163
},
167-
"friendly_name": "Elco Comfort room Temperature setpoint",
168164
}
169165
_post_data(
170166
"sensor.elco_comfort_room_temperature_setpoint",
171167
elco_comfort_room_temperature_setpoint,
172168
)
173169

174170
elco_reduced_room_temperature_setpoint = {
175-
"unique_id": "elco_reduced_room_temperature_setpoint",
176171
"state": zoneData["chReducedTemp"]["value"],
177172
"attributes": {
178173
"unit_of_measurement": "°C",
179174
"device_class": "temperature",
180175
"min": zoneData["chReducedTemp"]["min"],
181176
"max": zoneData["chReducedTemp"]["max"],
182177
"step": zoneData["chReducedTemp"]["step"],
178+
"friendly_name": "Elco Reduced room Temperature setpoint",
183179
},
184-
"friendly_name": "Elco Reduced room Temperature setpoint",
185180
}
186181
_post_data(
187182
"sensor.elco_reduced_room_temperature_setpoint",
188183
elco_reduced_room_temperature_setpoint,
189184
)
190185

191186
elco_room_temperature = {
192-
"unique_id": "elco_room_temperature",
193187
"state": zoneData["roomTemp"],
194188
"attributes": {
195189
"unit_of_measurement": "°C",
196190
"device_class": "temperature",
191+
"friendly_name": "Elco Room Temperature",
197192
},
198-
"friendly_name": "Elco Room Temperature",
199193
}
200194
_post_data("sensor.elco_room_temperature", elco_room_temperature)
201195

202196
elco_desired_room_temperature = {
203-
"unique_id": "elco_desired_room_temperature",
204197
"state": zoneData["desiredRoomTemp"],
205198
"attributes": {
206199
"unit_of_measurement": "°C",
207200
"device_class": "temperature",
201+
"friendly_name": "Elco Desired Room Temperature",
208202
},
209-
"friendly_name": "Elco Desired Room Temperature",
210203
}
211204
_post_data(
212205
"sensor.elco_desired_room_temperature", elco_desired_room_temperature
213206
)
214207

215208
mode_dict = {0: "Off", 1: "Comfort", 2: "Reduced", 3: "Frost Protection"}
216209
elco_room_operation_mode_heating = {
217-
"unique_id": "elco_room_operation_mode_heating",
218210
"state": mode_dict.get(zoneData["mode"]["value"]),
219-
"attributes": {},
220-
"icon": "mdi:radiator",
221-
"friendly_name": "Elco Room Operation mode heating",
211+
"attributes": {
212+
"icon": "mdi:radiator",
213+
"friendly_name": "Elco Room Operation mode heating",
214+
},
222215
}
223216
_post_data(
224217
"sensor.elco_room_operation_mode_heating",
225218
elco_room_operation_mode_heating,
226219
)
227220

228221
elco_room_heating_is_active = {
229-
"unique_id": "elco_room_heating_is_active",
230222
"state": "on" if zoneData["isHeatingActive"] == 1 else "off",
231223
"attributes": {
232224
"device_class": "running",
225+
"friendly_name": "Elco Room Heating is Active",
233226
},
234-
"friendly_name": "Elco Room Heating is Active",
235227
}
236228
_post_data(
237229
"binary_sensor.elco_room_heating_is_active", elco_room_heating_is_active
238230
)
239231

240232
elco_room_heating_is_request = {
241-
"unique_id": "elco_room_heating_is_request",
242233
"state": "on" if zoneData["heatOrCoolRequest"] == 1 else "off",
243234
"attributes": {
244235
"device_class": "problem",
236+
"friendly_name": "Elco Room Heating is Request",
245237
},
246-
"friendly_name": "Elco Room Heating is Request",
247238
}
248239
_post_data(
249240
"binary_sensor.elco_room_heating_is_request",
250241
elco_room_heating_is_request,
251242
)
252243

253244
try:
254-
if self.args["ha_url"]:
245+
if self.args.get("ha_url"):
255246
# get HA's url from app's first, if configured/overridden by user
256247
self.log("Using ha_url from app's configuration")
257248
ha_url = self.args["ha_url"]
258249
else:
250+
self.log("Using ha_url from plugins's HASS configuration")
259251
ha_url = self.config["plugins"]["HASS"]["ha_url"]
260252
except Exception as e:
261253
self.error(

0 commit comments

Comments
 (0)