Skip to content

Commit

Permalink
Feat/cosy 6 support (#1133)
Browse files Browse the repository at this point in the history
  • Loading branch information
BottlecapDave authored Dec 21, 2024
2 parents 7c34262 + 3eff36e commit 3466ec5
Show file tree
Hide file tree
Showing 15 changed files with 130 additions and 149 deletions.
6 changes: 6 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ jobs:
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Install dependencies
run: sudo apt install libffi-dev libncurses5-dev zlib1g zlib1g-dev libssl-dev libreadline-dev libbz2-dev libsqlite3-dev
shell: bash
- name: asdf_install
uses: asdf-vm/actions/install@v3
- name: Install Python modules
Expand All @@ -55,6 +58,9 @@ jobs:
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Install dependencies
run: sudo apt install libffi-dev libncurses5-dev zlib1g zlib1g-dev libssl-dev libreadline-dev libbz2-dev libsqlite3-dev
shell: bash
- name: asdf_install
uses: asdf-vm/actions/install@v3
- name: Install Python modules
Expand Down
35 changes: 2 additions & 33 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,45 +1,14 @@
# [13.3.0-beta.4](https://github.com/BottlecapDave/HomeAssistant-OctopusEnergy/compare/v13.3.0-beta.3...v13.3.0-beta.4) (2024-12-15)
# [13.3.0](https://github.com/BottlecapDave/HomeAssistant-OctopusEnergy/compare/v13.2.1...v13.3.0) (2024-12-16)


### Bug Fixes

* Fixed issue with downloading diagnostics breaks loading of data (15 minutes dev time) ([4589a6a](https://github.com/BottlecapDave/HomeAssistant-OctopusEnergy/commit/4589a6ad0565e4289d3de2d89b525e6110e0605b))
* Fixed zone mode interpretations in zone climate control and exposed target temperature in boost service (30 minutes dev time) ([7eb6755](https://github.com/BottlecapDave/HomeAssistant-OctopusEnergy/commit/7eb67553119773616097b6cc9360e03ed793fb46))
* Fixed issue with gas tariff comparison not persisting configured calorific value (1 hour dev time) ([b16cd1d](https://github.com/BottlecapDave/HomeAssistant-OctopusEnergy/commit/b16cd1dbeeac4224d62c4cdf05b0c845a3ac71dd))


### Features

* Updated heat pump zones and sensors to not be included if not enabled (5 minutes dev time) ([f762c4d](https://github.com/BottlecapDave/HomeAssistant-OctopusEnergy/commit/f762c4d214ba635abc8447536a75e4e1402ffea1))

# [13.3.0-beta.3](https://github.com/BottlecapDave/HomeAssistant-OctopusEnergy/compare/v13.3.0-beta.2...v13.3.0-beta.3) (2024-12-14)


### Features

* Created heat pump boosting action to support custom end time (40 minutes dev time) ([bc047f8](https://github.com/BottlecapDave/HomeAssistant-OctopusEnergy/commit/bc047f866a2047cd3d2cc059cce362d2f56a2ada))
* Fixed heat pump service calls (30 minutes dev time) ([ff88cd4](https://github.com/BottlecapDave/HomeAssistant-OctopusEnergy/commit/ff88cd419b626daccb10d236a772b27931a4f08a))
* Updated heat pump zone min/max temperatures based on zone type (5 minutes dev time) ([2ce5fe6](https://github.com/BottlecapDave/HomeAssistant-OctopusEnergy/commit/2ce5fe64456434552d581aaaa311030fa0cec8f4))

# [13.3.0-beta.2](https://github.com/BottlecapDave/HomeAssistant-OctopusEnergy/compare/v13.3.0-beta.1...v13.3.0-beta.2) (2024-12-11)


### Bug Fixes

* Fixed heat pump retrieved at parsing (15 minutes dev time) ([cd47109](https://github.com/BottlecapDave/HomeAssistant-OctopusEnergy/commit/cd471094811f120a56c6fa4a7498d532ad32a3bc))
* Fixed heat pump retrieved at parsing (15 minutes dev time) ([#1118](https://github.com/BottlecapDave/HomeAssistant-OctopusEnergy/issues/1118)) ([aeac537](https://github.com/BottlecapDave/HomeAssistant-OctopusEnergy/commit/aeac537b1624e1b6bbcb4e8d9089ae44d9ee3f09))

# [13.3.0-beta.1](https://github.com/BottlecapDave/HomeAssistant-OctopusEnergy/compare/v13.2.1...v13.3.0-beta.1) (2024-12-10)


### Features

* Added ability to change zone modes and target temperatures (1 hour dev time) ([56aef85](https://github.com/BottlecapDave/HomeAssistant-OctopusEnergy/commit/56aef85031be5e4b9a5bb5621b042a5616304fc7))
* Added climate control for heat pump zone (3 hours dev time) ([5e72161](https://github.com/BottlecapDave/HomeAssistant-OctopusEnergy/commit/5e72161a180119110be950322dfafeab6b755b27))
* Added endpoint to get heat pump configuration and status ([1826925](https://github.com/BottlecapDave/HomeAssistant-OctopusEnergy/commit/1826925513a288bc1b6a4772c305deb7cf3dc6d6))
* Added heat pump humidity sensor (1 hour dev time) ([b479c89](https://github.com/BottlecapDave/HomeAssistant-OctopusEnergy/commit/b479c8999256a70273077c8c0b5f001decbdbf84))
* Added heat pump information to device diagnostics (30 minutes dev time) ([b8468bc](https://github.com/BottlecapDave/HomeAssistant-OctopusEnergy/commit/b8468bce31a4dff419b3bfe21392911b88f05f0d))
* Added temperature sensors from heat pumps (2.5 hours dev time) ([c79e5b8](https://github.com/BottlecapDave/HomeAssistant-OctopusEnergy/commit/c79e5b8bdb50ee974027e2f5d9a7a16360634621))
* Updated account to include heat pump ids (5 minutes dev time) ([5c411c8](https://github.com/BottlecapDave/HomeAssistant-OctopusEnergy/commit/5c411c8efafc41ca323ae4d8415f03cb213da282))
* Updated cost tracker entities to be associated with device of tracked entity, if one exists (1 hour dev time) ([9fe69a0](https://github.com/BottlecapDave/HomeAssistant-OctopusEnergy/commit/9fe69a081b08f1bec3ecfb4ea3b4ed552cc665ef))

## [13.2.1](https://github.com/BottlecapDave/HomeAssistant-OctopusEnergy/compare/v13.2.0...v13.2.1) (2024-12-01)
Expand Down
25 changes: 24 additions & 1 deletion custom_components/octopus_energy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,12 @@ async def async_close_connection(_) -> None:
# the correct references (e.g. rate coordinators)
child_entries = hass.config_entries.async_entries(DOMAIN)
for child_entry in child_entries:
if child_entry.data[CONFIG_KIND] != CONFIG_KIND_ACCOUNT and child_entry.data[CONFIG_ACCOUNT_ID] == account_id:
child_entry_config = dict(child_entry.data)

if child_entry.options:
child_entry_config.update(child_entry.options)

if child_entry_config[CONFIG_KIND] != CONFIG_KIND_ACCOUNT and child_entry_config[CONFIG_ACCOUNT_ID] == account_id:
await hass.config_entries.async_reload(child_entry.entry_id)

elif config[CONFIG_KIND] == CONFIG_KIND_TARGET_RATE:
Expand Down Expand Up @@ -472,6 +477,21 @@ async def options_update_listener(hass, entry):
"""Handle options update."""
await hass.config_entries.async_reload(entry.entry_id)

if entry.data[CONFIG_KIND] == CONFIG_KIND_ACCOUNT:
account_id = entry.data[CONFIG_ACCOUNT_ID]

# If the main account has been reloaded, then reload all other entries to make sure they're referencing
# the correct references (e.g. rate coordinators)
child_entries = hass.config_entries.async_entries(DOMAIN)
for child_entry in child_entries:
child_entry_config = dict(child_entry.data)

if child_entry.options:
child_entry_config.update(child_entry.options)

if child_entry_config[CONFIG_KIND] != CONFIG_KIND_ACCOUNT and child_entry_config[CONFIG_ACCOUNT_ID] == account_id:
await hass.config_entries.async_reload(child_entry.entry_id)

async def async_unload_entry(hass, entry):
"""Unload a config entry."""

Expand All @@ -483,6 +503,9 @@ async def async_unload_entry(hass, entry):
await _async_close_client(hass, account_id)
hass.data[DOMAIN].pop(account_id)

elif entry.data[CONFIG_KIND] == CONFIG_KIND_TARIFF_COMPARISON:
unload_ok = await hass.config_entries.async_unload_platforms(entry, TARIFF_COMPARISON_PLATFORMS)

elif entry.data[CONFIG_KIND] == CONFIG_KIND_TARGET_RATE or entry.data[CONFIG_KIND] == CONFIG_KIND_ROLLING_TARGET_RATE:
unload_ok = await hass.config_entries.async_unload_platforms(entry, TARGET_RATE_PLATFORMS)

Expand Down
35 changes: 20 additions & 15 deletions custom_components/octopus_energy/api_client_home_pro/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,10 @@ def _create_client_session(self):
async def async_ping(self):
try:
client = self._create_client_session()
url = f'{self._base_url}/get_meter_info?meter_type=elec'
url = f'{self._base_url}:3000/get_meter_consumption'
headers = { "Authorization": self._api_key }
async with client.get(url, headers=headers) as response:
data = { "meter_type": "elec" }
async with client.post(url, headers=headers, json=data) as response:
response_body = await self.__async_read_response__(response, url)
if (response_body is not None and "Status" in response_body):
status: str = response_body["Status"]
Expand All @@ -62,20 +63,23 @@ async def async_get_consumption(self, is_electricity: bool) -> list | None:
try:
client = self._create_client_session()
meter_type = 'elec' if is_electricity else 'gas'
url = f'{self._base_url}/get_meter_consumption?meter_type={meter_type}'
url = f'{self._base_url}:3000/get_meter_consumption'
headers = { "Authorization": self._api_key }
async with client.get(url, headers=headers) as response:
data = { "meter_type": meter_type }
async with client.post(url, headers=headers, json=data) as response:
response_body = await self.__async_read_response__(response, url)
if (response_body is not None and "meter_consump" in response_body and "consum" in response_body["meter_consump"]):
data = response_body["meter_consump"]["consum"]
divisor = int(data["raw"]["divisor"], 16)
return [{
"total_consumption": int(data["consumption"]) / divisor if divisor > 0 else None,
"demand": float(data["instdmand"]) if "instdmand" in data else None,
"start": datetime.fromtimestamp(int(response_body["meter_consump"]["time"]), timezone.utc),
"end": datetime.fromtimestamp(int(response_body["meter_consump"]["time"]), timezone.utc),
"is_kwh": data["unit"] == 0
}]
if (response_body is not None and "meter_consump"):
meter_consump = json.loads(response_body["meter_consump"])
if "consum" in meter_consump:
data = meter_consump["consum"]
divisor = int(data["raw"]["divisor"], 16)
return [{
"total_consumption": int(data["consumption"]) / divisor if divisor > 0 else None,
"demand": float(data["instdmand"]) if "instdmand" in data else None,
"start": datetime.fromtimestamp(int(meter_consump["time"]), timezone.utc),
"end": datetime.fromtimestamp(int(meter_consump["time"]), timezone.utc),
"is_kwh": data["unit"] == 0
}]

return None

Expand All @@ -88,7 +92,7 @@ async def async_set_screen(self, value: str, animation_type: str, type: str, bri

try:
client = self._create_client_session()
url = f'{self._base_url}/screen'
url = f'{self._base_url}:8000/screen'
headers = { "Authorization": self._api_key }
payload = {
# API doesn't support none or empty string as a valid value
Expand All @@ -110,6 +114,7 @@ async def __async_read_response__(self, response, url):
"""Reads the response, logging any json errors"""

text = await response.text()
_LOGGER.debug(f"response: {text}")

if response.status >= 400:
if response.status >= 500:
Expand Down
4 changes: 4 additions & 0 deletions custom_components/octopus_energy/config/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ async def async_migrate_main_config(version: int, data: {}):
new_data[CONFIG_ACCOUNT_ID] = new_data[CONFIG_MAIN_OLD_ACCOUNT_ID]
del new_data[CONFIG_MAIN_OLD_ACCOUNT_ID]

if (version <= 5):
if CONFIG_MAIN_HOME_PRO_ADDRESS in new_data:
new_data[CONFIG_MAIN_HOME_PRO_ADDRESS] = f"{new_data[CONFIG_MAIN_HOME_PRO_ADDRESS]}".replace(":8000", "")

return new_data

def merge_main_config(data: dict, options: dict, updated_config: dict = None):
Expand Down
4 changes: 2 additions & 2 deletions custom_components/octopus_energy/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import homeassistant.helpers.config_validation as cv

DOMAIN = "octopus_energy"
INTEGRATION_VERSION = "13.3.0-beta.4"
INTEGRATION_VERSION = "13.3.0"

REFRESH_RATE_IN_MINUTES_ACCOUNT = 60
REFRESH_RATE_IN_MINUTES_INTELLIGENT = 3
Expand All @@ -18,7 +18,7 @@
REFRESH_RATE_IN_MINUTES_HOME_PRO_CONSUMPTION = 0.17
REFRESH_RATE_IN_MINUTES_HEAT_PUMP = 1

CONFIG_VERSION = 4
CONFIG_VERSION = 5

CONFIG_KIND = "kind"
CONFIG_KIND_ACCOUNT = "account"
Expand Down
3 changes: 3 additions & 0 deletions custom_components/octopus_energy/heat_pump/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ def __init__(self, hass: HomeAssistant, heat_pump_id: str, heat_pump: HeatPump,
identifiers={(DOMAIN, f"heat_pump_{heat_pump.serialNumber}")},
name=f"Heat Pump ({heat_pump.serialNumber})",
connections=set(),
manufacturer="Octopus" if heat_pump.model is not None and "cosy" in heat_pump.model.lower() else None,
model=heat_pump.model,
hw_version=heat_pump.hardwareVersion
)
Expand All @@ -48,6 +49,8 @@ def __init__(self, hass: HomeAssistant, heat_pump_id: str, heat_pump: HeatPump,
identifiers={(DOMAIN, f"heat_pump_sensor_{heat_pump.serialNumber}_{sensor.code}")},
name=f"Heat Pump Sensor ({sensor.code})",
connections=set(),
manufacturer="Octopus" if heat_pump.model is not None and "cosy" in heat_pump.model.lower() else None,
model=heat_pump.model,
sw_version=sensor.firmwareVersion,
hw_version=sensor.type
)
Loading

0 comments on commit 3466ec5

Please sign in to comment.