Skip to content

Commit

Permalink
Added simple cover platform.
Browse files Browse the repository at this point in the history
  • Loading branch information
StephanU committed Mar 19, 2023
1 parent fff3ffd commit 6003b26
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 5 deletions.
4 changes: 2 additions & 2 deletions custom_components/mygekko/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry):
gekkoid = entry.data.get(CONF_GEKKOID)

session = async_get_clientsession(hass)
client = PyMyGekkoApiClient(username, apikey, gekkoid)
client = PyMyGekkoApiClient(username, apikey, gekkoid, session)

coordinator = MyGekkoDataUpdateCoordinator(hass, client=client)
await coordinator.async_refresh()
Expand Down Expand Up @@ -84,7 +84,7 @@ def __init__(
async def _async_update_data(self):
"""Update data via library."""
try:
return await self.api.async_get_data()
return await self.api.read_data()
except Exception as exception:
raise UpdateFailed() from exception

Expand Down
2 changes: 1 addition & 1 deletion custom_components/mygekko/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ async def _test_credentials(self, username, apikey, gekkoid):
"""Return true if credentials is valid."""
try:
session = async_create_clientsession(self.hass)
client = PyMyGekkoApiClient(username, apikey, gekkoid)
client = PyMyGekkoApiClient(username, apikey, gekkoid, session)
await client.try_connect()
return True
except Exception: # pylint: disable=broad-except
Expand Down
3 changes: 2 additions & 1 deletion custom_components/mygekko/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
BINARY_SENSOR = "binary_sensor"
SENSOR = "sensor"
SWITCH = "switch"
PLATFORMS = [BINARY_SENSOR, SENSOR, SWITCH]
COVER = "cover"
PLATFORMS = [BINARY_SENSOR, SENSOR, SWITCH, COVER]


# Configuration and options
Expand Down
20 changes: 20 additions & 0 deletions custom_components/mygekko/cover.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
"""Cover platform for MyGekko."""

from homeassistant.components.cover import CoverEntity, CoverDeviceClass

from .const import DOMAIN
from .entity import MyGekkoEntity


async def async_setup_entry(hass, entry, async_add_devices):
"""Setup cover platform."""
coordinator = hass.data[DOMAIN][entry.entry_id]
async_add_devices([MyGekkoCover(coordinator, entry)])


class MyGekkoCover(MyGekkoEntity, CoverEntity):
"""mygekko Cover class."""

def __init__(self, coordinator, config_entry):
super().__init__(coordinator, config_entry)
self.device_class = CoverDeviceClass.BLIND
2 changes: 1 addition & 1 deletion custom_components/mygekko/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@
"dependencies": [],
"config_flow": true,
"codeowners": ["@stephanu"],
"requirements": ["pymygekko==0.0.3"]
"requirements": ["pymygekko==0.0.4rc0"]
}

0 comments on commit 6003b26

Please sign in to comment.