Skip to content
This repository has been archived by the owner on Jan 5, 2024. It is now read-only.

Commit

Permalink
Merge pull request #2 from rccoleman/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
rccoleman authored Nov 29, 2020
2 parents b5e2d2e + eda8772 commit d39f750
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 15 deletions.
15 changes: 9 additions & 6 deletions custom_components/lamarzocco/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@ async def async_setup_entry(hass, config_entry):

hass.data[DOMAIN][config_entry.entry_id] = coordinator

for component in PLATFORMS:
for platform in PLATFORMS:
hass.async_create_task(
hass.config_entries.async_forward_entry_setup(config_entry, component)
hass.config_entries.async_forward_entry_setup(config_entry, platform)
)

return True
Expand Down Expand Up @@ -96,14 +96,18 @@ def __init__(self, hass, config_entry):
self.hass = hass

super().__init__(
hass, _LOGGER, name=DOMAIN, update_interval=timedelta(seconds=60)
hass,
_LOGGER,
name=DOMAIN,
update_interval=timedelta(seconds=60),
update_method=self.async_update_data,
)

def init_data(self):
"""Initialize the UpdateCoordinator object"""
self._device.init_data()

async def _async_update_data(self):
async def async_update_data(self):
"""Fetch data"""
try:
return await self._device.fetch_data()
Expand All @@ -125,15 +129,14 @@ def __init__(self, hass, config):
def init_data(self):
"""Machine data inialization"""
serial_number = self._config[CONF_SERIAL_NUMBER]
token_endpoint = "https://cms.lamarzocco.io/oauth/v2/token"
self.config_endpoint = f"{GW_URL}/{serial_number}/configuration"
self.status_endpoint = f"{GW_URL}/{serial_number}/status"
self.client = OAuth2Session(
client=oauthlib.oauth2.LegacyApplicationClient(self._config[CONF_CLIENT_ID])
)

self.client.fetch_token(
token_endpoint,
"https://cms.lamarzocco.io/oauth/v2/token",
client_secret=self._config[CONF_CLIENT_SECRET],
username=self._config[CONF_USERNAME],
password=self._config[CONF_PASSWORD],
Expand Down
2 changes: 1 addition & 1 deletion custom_components/lamarzocco/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"unknown": "[%key:common::config_flow::error::unknown%]"
},
"abort": {
"already_configured": "[%key:common::config_flow::abort::already_configured_device%]"
"single_instance_allowed": "[%key:common::config_flow::abort::single_instance_allowed%]"
}
}
}
10 changes: 3 additions & 7 deletions custom_components/lamarzocco/switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,11 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
"""Add a switch entity from a config_entry."""
coordinator = hass.data[DOMAIN][config_entry.entry_id]
async_add_entities(
[
LaMarzocco(coordinator, config_entry.data, hass.config.units.is_metric),
]
[LaMarzoccoEntity(coordinator, config_entry.data, hass.config.units.is_metric)]
)


class LaMarzocco(CoordinatorEntity, SwitchEntity, RestoreEntity):
class LaMarzoccoEntity(CoordinatorEntity, SwitchEntity, RestoreEntity):
"""Implementation of a La Marzocco integration"""

def __init__(self, coordinator, config, is_metric):
Expand All @@ -39,21 +37,19 @@ def turn_on(self, **kwargs) -> None:
"""Turn device on."""
self.coordinator.data.power(True)
self._temp_state = True

self.schedule_update_ha_state(force_refresh=False)

def turn_off(self, **kwargs) -> None:
"""Turn device off."""
self.coordinator.data.power(False)
self._temp_state = False

self.schedule_update_ha_state(force_refresh=False)

@callback
def _handle_coordinator_update(self) -> None:
"""Respond to a DataUpdateCoordinator update."""
self.update_from_latest_data()
self.async_write_ha_state()
super()._handle_coordinator_update()

@callback
def update_from_latest_data(self) -> None:
Expand Down
2 changes: 1 addition & 1 deletion custom_components/lamarzocco/translations/en.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"config": {
"abort": {
"already_configured": "Device is already configured"
"single_instance_allowed": "Device is already configured. On a single instance is allowed."
},
"error": {
"cannot_connect": "Failed to connect",
Expand Down

0 comments on commit d39f750

Please sign in to comment.