Skip to content

Commit

Permalink
schedule, many more.
Browse files Browse the repository at this point in the history
  • Loading branch information
pszafer committed Nov 5, 2019
1 parent 3cd3fda commit 6e17562
Show file tree
Hide file tree
Showing 24 changed files with 270 additions and 1,045 deletions.
812 changes: 0 additions & 812 deletions all_request_doc.txt

This file was deleted.

37 changes: 23 additions & 14 deletions bosch_thermostat_http/circuit.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,9 @@
SUBMIT,
REFS,
HA_STATES,
MANUAL_SETPOINT,
AUTO_SETPOINT,
ACTIVE_PROGRAM,
STATUS
)
from .helper import BoschSingleEntity, crawl
from .helper import BoschSingleEntity
from .errors import ResponseError
from .schedule import Schedule

Expand All @@ -32,6 +30,7 @@ def __init__(self, requests, attr_id, db, str_obj, _type, current_date):
self._requests = requests
name = attr_id.split("/").pop()
self._type = _type
self._state = False
if self._type == HC:
self._db = db[HEATING_CIRCUITS]
else:
Expand Down Expand Up @@ -59,28 +58,31 @@ def current_mode(self):

@property
def available_operation_modes(self):
"""Get Bosch operations modes."""
return self.get_property(OPERATION_MODE).get(self.strings.allowed_values, {})

async def initialize(self):
"""Check each uri if return json with values."""
refs = self._db[REFS]
for key, value in refs.items():
for key, value in self._db[REFS].items():
uri = value[ID].format(self.name)
result = await crawl(uri, [], 1, self._requests[GET])
_LOGGER.debug("INITIALIZING uri %s with result %s", uri, result)
self._circuits_path[key] = uri
self._data[key] = {}
self._json_scheme_ready = True
await self.update_requested_key(STATUS)

async def update(self):
"""Update info about Circuit asynchronously."""
_LOGGER.debug("Updating circuit %s", self.name)
is_updated = False
for key in self._data:
result = await self._requests[GET](self._circuits_path[key])
if self.process_results(result, key):
is_updated = True
self._updated_initialized = True
try:
for key in self._data:
result = await self._requests[GET](self._circuits_path[key])
if self.process_results(result, key):
is_updated = True
self._updated_initialized = True
self._state = True
except ResponseError:
self._state = False
return is_updated

async def update_requested_key(self, key):
Expand All @@ -89,8 +91,9 @@ async def update_requested_key(self, key):
try:
result = await self._requests[GET](self._circuits_path[key])
self.process_results(result, key)
self._state = True
except ResponseError:
pass
self._state = False

async def set_operation_mode(self, new_mode):
"""Set operation_mode of Heating Circuit."""
Expand All @@ -107,6 +110,12 @@ async def set_operation_mode(self, new_mode):
self.available_operation_modes,
)

@property
def state(self):
"""Retrieve state of the circuit."""
if self._state:
return self.get_value(STATUS)

@property
def current_temp(self):
"""Give current temperature of circuit."""
Expand Down
23 changes: 14 additions & 9 deletions bosch_thermostat_http/circuits.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""Circuits module of Bosch thermostat."""
from .const import HC, HEATING_CIRCUITS, DHW_CIRCUITS, MAIN_URI
from .const import HC, HEATING_CIRCUITS, DHW_CIRCUITS, MAIN_URI, ID
from .helper import BoschEntities


Expand All @@ -13,8 +13,7 @@ def __init__(self, requests, circuit_type):
:param dict requests: { GET: get function, SUBMIT: submit function}
:param str circuit_type: is it HC or DHW
"""
self._circuit_type = (HEATING_CIRCUITS if circuit_type == HC else
DHW_CIRCUITS)
self._circuit_type = HEATING_CIRCUITS if circuit_type == HC else DHW_CIRCUITS
super().__init__(requests)

@property
Expand All @@ -29,19 +28,25 @@ async def initialize(self, database, str_obj, current_date):
for circuit in circuits:
if "references" in circuit:
circuit_object = self.create_circuit(
circuit, database, str_obj, current_date)
circuit, database, str_obj, current_date
)
if circuit_object:
await circuit_object.initialize()
self._items.append(circuit_object)
if circuit_object.state:
self._items.append(circuit_object)

def create_circuit(self, circuit, database, str_obj, current_date):
"""Create single circuit of given type."""
if self._circuit_type == DHW_CIRCUITS:
from .dhw_circuit import DHWCircuit
return DHWCircuit(self._requests, circuit['id'],
database, str_obj, current_date)

return DHWCircuit(
self._requests, circuit[ID], database, str_obj, current_date
)
if self._circuit_type == HEATING_CIRCUITS:
from .heating_circuit import HeatingCircuit
return HeatingCircuit(self._requests, circuit['id'], database,
str_obj, current_date)

return HeatingCircuit(
self._requests, circuit[ID], database, str_obj, current_date
)
return None
14 changes: 11 additions & 3 deletions bosch_thermostat_http/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@
HCPROGRAM = "hcprogram"
CURRENT_TEMP = "current_temp"
AUTO_SETPOINT = "auto_setpoint"
MANUAL_SETPOINT = "manual_setpoint"
AUTO_SETTEMP = "auto_set_temp"
WATER_SETPOINT = "water_setpoint"
WATER_OFF = "water_off"
WATER_HIGH = "water_high"
Expand All @@ -60,6 +58,8 @@

INVALID = "invalid"

DEFAULT_SENSORS = "defaultSensors"

ROOT_PATHS = ["/dhwCircuits", "/gateway", "/heatingCircuits",
"/heatSources", "/notifications", "/system"]

Expand All @@ -81,6 +81,10 @@
HEATING_CIRCUITS = "heatingCircuits"
DHW_CIRCUITS = "dhwCircuits"

MODE_TO_SETPOINT = "mode_to_setpoint"
READ = "read"
WRITE = "write"

RC300 = "RC300"

###SCHEDULE
Expand All @@ -97,4 +101,8 @@
"Fr": "friday",
"Sa": "saturday",
"Su": "sunday",
}
}

SENSORS_LIST = ["outdoor_t1", "hotWater_t2", "supply_t1_setpoint", "supply_t1",
"return", "healthStatus", "actualPower", "actualModulation",
"CHpumpModulation"]
48 changes: 11 additions & 37 deletions bosch_thermostat_http/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,10 @@
import json
import os

from .const import (PATHS, GATEWAY, DICT, GATEWAY, HEATING_CIRCUITS,
DHW_CIRCUITS, MANUAL, AUTO, MAX, MIN, UNITS, STATE,
INVALID, VALUE, ALLOWED_VALUES, OWNPROGRAM, HCPROGRAM,
OPEN, SHORT, UUID, FIRMWARE_VERSION, HARDWARE_VERSION,
SYSTEM_BRAND, SYSTEM_TYPE, MAIN_URI, REFS, RC300)
from .const import RC300

MAINPATH = os.path.join(os.path.dirname(__file__), 'db')
FILENAME = os.path.join(MAINPATH, 'db.json')
MAINPATH = os.path.join(os.path.dirname(__file__), "db")
FILENAME = os.path.join(MAINPATH, "db.json")

DATA = "data"
FIRMWARE_URI = "versionFirmwarePath"
Expand All @@ -19,45 +15,23 @@

def open_json(file):
"""Open json file."""
with open(file, 'r') as f:
with open(file, "r") as f:
datastore = json.load(f)
return datastore
return None


def get_firmware_uri():
datastore = open_json(FILENAME)
if FIRMWARE_URI in datastore:
return datastore[FIRMWARE_URI]
return None

def get_initial_db():
"""Get initial db. Same for all devices."""
return open_json(FILENAME)


def get_db_of_firmware(device_type, firmware_version):
"""Get db of specific device."""
filename = "rc300.json" if device_type == RC300 else "default.json"
filepath = os.path.join(MAINPATH, filename)
db = open_json(filepath)
if db:
if firmware_version in db:
return db[firmware_version]
_db = open_json(filepath)
if _db:
if firmware_version in _db:
return _db[firmware_version]
return None

def check_db(fw_version, db):
return True
if fw_version in db:
subrow = db[fw_version]
if DICT in subrow and GATEWAY in subrow:
if not all(k in subrow[DICT] for k in (MANUAL, AUTO, MAX, MIN,
UNITS, STATE, INVALID,
VALUE, ALLOWED_VALUES,
OWNPROGRAM, HCPROGRAM,
OPEN, SHORT)):
return False
if not all(k in subrow[DICT] for k in (UUID, FIRMWARE_VERSION,
HARDWARE_VERSION,
SYSTEM_BRAND, SYSTEM_TYPE)):
return False
else:
return False
return True
3 changes: 2 additions & 1 deletion bosch_thermostat_http/db/db.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@
"systemType": "/system/systemType",
"dateTime": "/gateway/DateTime"
},
"defaultSensors": ["outdoor_t1", "hotWater_t2"],
"value": "ES73",
"models": {
"76": {
"value": "ES73",
"name": "Sieger ES73",
"type": "default"
},
Expand Down
30 changes: 19 additions & 11 deletions bosch_thermostat_http/db/default.json
Original file line number Diff line number Diff line change
Expand Up @@ -104,44 +104,52 @@
}
}
},
"sensors": [
{
"sensors": {
"outdoor_t1": {
"id": "/system/sensors/temperatures/outdoor_t1",
"name": "Outdoor temperature"
},
{
"hotWater_t2": {
"id": "/system/sensors/temperatures/hotWater_t2",
"name": "Hotwater temp"
},
{
"supply_t1_setpoint": {
"id": "/system/sensors/temperatures/supply_t1_setpoint",
"name": "Supply temp setpoint"
},
{
"supply_t1": {
"id": "/system/sensors/temperatures/supply_t1",
"name": "Actual supply temp"
},
{
"return": {
"id": "/system/sensors/temperatures/return",
"name": "Return temp"
},
{
"healthStatus": {
"id": "/system/healthStatus",
"name": "Health status"
},
{
"actualPower": {
"id": "/heatSources/actualPower",
"name": "Actual Power"
},
{
"actualModulation": {
"id": "/heatSources/actualModulation",
"name": "Actual modulation"
},
{
"CHpumpModulation": {
"id": "/heatSources/CHpumpModulation",
"name": "Actual heating pump modulation"
},
"totalSystem": {
"id": "/heatSources/workingTime/totalSystem",
"name": "Total system uptime mins"
},
"systemPressure": {
"id": "/heatSources/systemPressure",
"name": "System pressure"
}
],
},
"versionFirmware": "01.10.03"
}
}
Loading

0 comments on commit 6e17562

Please sign in to comment.