Skip to content

Commit

Permalink
Merge pull request #19 from PiotrMachowski/dev
Browse files Browse the repository at this point in the history
v1.1.5
  • Loading branch information
PiotrMachowski authored Jun 4, 2023
2 parents 3bf799d + cada835 commit 24cbd34
Show file tree
Hide file tree
Showing 7 changed files with 128 additions and 37 deletions.
3 changes: 2 additions & 1 deletion .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
custom: ["buymeacoffee.com/PiotrMachowski", "paypal.me/PiMachowski"]
ko_fi: piotrmachowski
custom: ["buycoffee.to/piotrmachowski", "paypal.me/PiMachowski", "revolut.me/314ma"]
121 changes: 106 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
[![HACS Default][hacs_shield]][hacs]
[![GitHub Latest Release][releases_shield]][latest_release]
[![GitHub All Releases][downloads_total_shield]][releases]
[![Community Forum][community_forum_shield]][community_forum]
[![Community Forum][community_forum_shield]][community_forum]<!-- piotrmachowski_support_badges_start -->
[![Ko-Fi][ko_fi_shield]][ko_fi]
[![buycoffee.to][buycoffee_to_shield]][buycoffee_to]
[![PayPal.Me][paypal_me_shield]][paypal_me]
[![Revolut.Me][revolut_me_shield]][revolut_me]
<!-- piotrmachowski_support_badges_end -->


[hacs_shield]: https://img.shields.io/static/v1.svg?label=HACS&message=Default&style=popout&color=green&labelColor=41bdf5&logo=HomeAssistantCommunityStore&logoColor=white
Expand All @@ -19,17 +21,6 @@
[community_forum_shield]: https://img.shields.io/static/v1.svg?label=%20&message=Forum&style=popout&color=41bdf5&logo=HomeAssistant&logoColor=white
[community_forum]: https://community.home-assistant.io/t/custom-component-saver/204249

[ko_fi_shield]: https://img.shields.io/static/v1.svg?label=%20&message=Ko-Fi&color=F16061&logo=ko-fi&logoColor=white
[ko_fi]: https://ko-fi.com/piotrmachowski

[buycoffee_to_shield]: https://shields.io/badge/buycoffee.to-white?style=flat&labelColor=white&logo=data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/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pRicy7OU5MAAAAASUVORK5CYII=
[buycoffee_to]: https://buycoffee.to/piotrmachowski

[buy_me_a_coffee_shield]: https://img.shields.io/static/v1.svg?label=%20&message=Buy%20me%20a%20coffee&color=6f4e37&logo=buy%20me%20a%20coffee&logoColor=white
[buy_me_a_coffee]: https://www.buymeacoffee.com/PiotrMachowski

[paypal_me_shield]: https://img.shields.io/static/v1.svg?label=%20&message=PayPal.Me&logo=paypal
[paypal_me]: https://paypal.me/PiMachowski

[![Open your Home Assistant instance and start setting up a new integration.](https://my.home-assistant.io/badges/config_flow_start.svg)](https://my.home-assistant.io/redirect/config_flow_start/?domain=saver)

Expand Down Expand Up @@ -178,6 +169,106 @@ script:
value: "Counter has value {{ state_attr('saver.saver', 'variables')['counter'] }}"
```

<a href='https://ko-fi.com/piotrmachowski' target='_blank'><img height='35px' src='https://az743702.vo.msecnd.net/cdn/kofi3.png?v=0' border='0' alt='Buy Me a Coffee at ko-fi.com' />
<a href="https://buycoffee.to/piotrmachowski" target="_blank"><img src="https://buycoffee.to/btn/buycoffeeto-btn-primary.svg" height="35px" alt="Postaw mi kawę na buycoffee.to"></a>
<a href="https://paypal.me/PiMachowski" target="_blank"><img src="https://www.paypalobjects.com/webstatic/mktg/logo/pp_cc_mark_37x23.jpg" border="0" alt="PayPal Logo" height="35px" style="height: auto !important;width: auto !important;"></a>
## Events

After the completion of the services mentioned before, the following events are fired:

| **Service Function** | **Event ID** | **Provided Arguments** |
|----------------------|------------------------------|------------------------|
| **execute** | event_saver_executed | script |
| **save_state** | event_saver_saved_entity | entity_id |
| **restore_state** | event_saver_restored | entity_id |
| **delete** | event_saver_deleted_entity | entity_id |
| **clear** | event_saver_cleared | |
| **set_variable** | event_saver_saved_variable | variable, value |
| **delete_variable** | event_saver_deleted_variable | variable |

The events can be used to trigger further automations that depend on the completion of the services. The documentation is provided [here](https://www.home-assistant.io/docs/automation/trigger/#event-trigger).


<!-- piotrmachowski_support_links_start -->

## Support

If you want to support my work with a donation you can use one of the following platforms:

<table>
<tr>
<th>Platform</th>
<th>Payment methods</th>
<th>Link</th>
<th>Comment</th>
</tr>
<tr>
<td>Ko-fi</td>
<td>
<li>PayPal</li>
<li>Credit card</li>
</td>
<td>
<a href='https://ko-fi.com/piotrmachowski' target='_blank'><img height='35px' src='https://az743702.vo.msecnd.net/cdn/kofi3.png?v=0' border='0' alt='Buy Me a Coffee at ko-fi.com' /></a>
</td>
<td>
<li>No fees</li>
<li>Single or monthly payment</li>
</td>
</tr>
<tr>
<td>buycoffee.to</td>
<td>
<li>BLIK</li>
<li>Bank transfer</li>
</td>
<td>
<a href="https://buycoffee.to/piotrmachowski" target="_blank"><img src="https://buycoffee.to/btn/buycoffeeto-btn-primary.svg" height="35px" alt="Postaw mi kawę na buycoffee.to"></a>
</td>
<td></td>
</tr>
<tr>
<td>PayPal</td>
<td>
<li>PayPal</li>
</td>
<td>
<a href="https://paypal.me/PiMachowski" target="_blank"><img src="https://www.paypalobjects.com/webstatic/mktg/logo/pp_cc_mark_37x23.jpg" border="0" alt="PayPal Logo" height="35px" style="height: auto !important;width: auto !important;"></a>
</td>
<td>
<li>No fees</li>
</td>
</tr>
<tr>
<td>Revolut</td>
<td>
<li>Revolut</li>
<li>Credit Card</li>
</td>
<td>
<a href="https://revolut.me/314ma" target="_blank"><img src="https://www.revolut.com/favicon/android-chrome-192x192.png" height="35px" alt="Revolut"></a>
</td>
<td>
<li>No fees</li>
</td>
</tr>
</table>


[ko_fi_shield]: https://img.shields.io/static/v1.svg?label=%20&message=Ko-Fi&color=F16061&logo=ko-fi&logoColor=white

[ko_fi]: https://ko-fi.com/piotrmachowski

[buycoffee_to_shield]: https://shields.io/badge/buycoffee.to-white?style=flat&labelColor=white&logo=data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAABhmlDQ1BJQ0MgcHJvZmlsZQAAKJF9kT1Iw1AUhU9TpaIVh1YQcchQnayIijhKFYtgobQVWnUweemP0KQhSXFxFFwLDv4sVh1cnHV1cBUEwR8QVxcnRRcp8b6k0CLGC4/3cd49h/fuA4R6malmxzigapaRisfEbG5FDLzChxB6MIZ+iZl6Ir2QgWd93VM31V2UZ3n3/Vm9St5kgE8knmW6YRGvE09vWjrnfeIwK0kK8TnxqEEXJH7kuuzyG+eiwwLPDBuZ1BxxmFgstrHcxqxkqMRTxBFF1ShfyLqscN7irJarrHlP/sJgXltOc53WEOJYRAJJiJBRxQbKsBClXSPFRIrOYx7+QcefJJdMrg0wcsyjAhWS4wf/g9+zNQuTE25SMAZ0vtj2xzAQ2AUaNdv+PrbtxgngfwautJa/UgdmPkmvtbTIEdC3DVxctzR5D7jcAQaedMmQHMlPSygUgPcz+qYcELoFulfduTXPcfoAZGhWSzfAwSEwUqTsNY93d7XP7d+e5vx+AIahcq//o+yoAAAABmJLR0QA/wD/AP+gvaeTAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAB3RJTUUH5wETCy4vFNqLzwAAAVpJREFUOMvd0rFLVXEYxvHPOedKJnKJhrDLuUFREULE7YDCMYj+AydpsCWiaKu29hZxiP4Al4aWwC1EdFI4Q3hqEmkIBI8ZChWXKNLLvS0/Qcza84V3enm/7/s878t/HxGkeTaIGziP+EB918nawu7Dq1d0e1+2J2bepnk2jFEUVVF+qKV51o9neBCaugfge70keoxxUbSWjrQ+4SUyzKZ5NlnDZdzGG7w4DIh+dtZEFntDA98l8S0MYwctNGrYz9WqKJePFLq80g5Sr+EHlnATp+NA+4qLaZ7FfzMrzbMBjGEdq8GrJMZnvAvFC/8wfAwjWMQ8XmMzaW9sdevNRgd3MFhvNpbaG1u/Dk2/hOc4gadVUa7Um425qii/7Z+xH9O4jwW8Cqv24Tru4hyeVEU588cfBMgpPMI9nMFe0BkFzVOYrYqycyQgQJLwTC2cDZCPeF8V5Y7jGb8BUpRicy7OU5MAAAAASUVORK5CYII=

[buycoffee_to]: https://buycoffee.to/piotrmachowski

[buy_me_a_coffee_shield]: https://img.shields.io/static/v1.svg?label=%20&message=Buy%20me%20a%20coffee&color=6f4e37&logo=buy%20me%20a%20coffee&logoColor=white

[buy_me_a_coffee]: https://www.buymeacoffee.com/PiotrMachowski

[paypal_me_shield]: https://img.shields.io/static/v1.svg?label=%20&message=PayPal.Me&logo=paypal

[paypal_me]: https://paypal.me/PiMachowski

[revolut_me_shield]: https://img.shields.io/static/v1.svg?label=%20&message=Revolut&logo=revolut

[revolut_me]: https://revolut.me/314ma
<!-- piotrmachowski_support_links_end -->
13 changes: 9 additions & 4 deletions custom_components/saver/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import logging
import asyncio

from homeassistant.core import Context
from homeassistant.helpers.restore_state import RestoreEntity
Expand Down Expand Up @@ -29,39 +28,46 @@ def setup_entry(hass, config_entry):

def clear(call):
saver_entity.clear()
hass.bus.fire('event_saver_cleared')

def delete(call):
data = call.data
entity_id = data[CONF_ENTITY_ID]
saver_entity.delete(entity_id)
hass.bus.fire('event_saver_deleted_entity', {'entity_id': entity_id})

def delete_variable(call):
data = call.data
variable = data[CONF_NAME]
saver_entity.delete_variable(variable)
hass.bus.fire('event_saver_deleted_variable', {'variable': variable})

def execute(call):
data = call.data
script = data[CONF_SCRIPT]
saver_entity.execute(script)
hass.bus.fire('event_saver_executed', {'script': script})

def restore_state(call):
data = call.data
entity_id = data[CONF_ENTITY_ID]
restore_script = data[CONF_RESTORE_SCRIPT]
should_delete = data[CONF_DELETE_AFTER_RUN]
saver_entity.restore(entity_id, restore_script, should_delete)
hass.bus.fire('event_saver_restored', {'entity_id': entity_id})

def save_state(call):
data = call.data
entity_id = data[CONF_ENTITY_ID]
saver_entity.save(entity_id)
hass.bus.fire('event_saver_saved_entity', {'entity_id': entity_id})

def set_variable(call):
data = call.data
name = data[CONF_NAME]
value = data[CONF_VALUE]
saver_entity.set_variable(name, value)
hass.bus.fire('event_saver_saved_variable', {'variable': name, 'value': value})

hass.services.register(DOMAIN, SERVICE_CLEAR, clear, SERVICE_CLEAR_SCHEMA)
hass.services.register(DOMAIN, SERVICE_DELETE, delete, SERVICE_DELETE_SCHEMA)
Expand Down Expand Up @@ -146,9 +152,8 @@ def state_attributes(self):
def state(self):
return len(self._entities_db) + len(self._variables_db)

@asyncio.coroutine
def async_added_to_hass(self):
state = yield from self.async_get_last_state()
async def async_added_to_hass(self):
state = await self.async_get_last_state()
if state is not None \
and state.attributes is not None \
and "variables" in state.attributes and not isinstance(state.attributes["entities"], list) \
Expand Down
10 changes: 5 additions & 5 deletions custom_components/saver/manifest.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"domain": "saver",
"name": "Saver",
"codeowners": ["@PiotrMachowski"],
"config_flow": true,
"dependencies": [],
"documentation": "https://github.com/PiotrMachowski/Home-Assistant-custom-components-Saver",
"iot_class": "calculated",
"issue_tracker": "https://github.com/PiotrMachowski/Home-Assistant-custom-components-Saver/issues",
"dependencies": [],
"codeowners": ["@PiotrMachowski"],
"requirements": [],
"config_flow": true,
"version": "v1.1.4",
"iot_class": "calculated"
"version": "v1.1.5"
}
6 changes: 2 additions & 4 deletions custom_components/saver/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@
},
"step": {
"user": {
"description": "Do you want to configure the Saver?",
"title": "Saver"
"description": "Do you want to configure the Saver?"
}
},
"title": "Saver"
}
}
}
6 changes: 2 additions & 4 deletions custom_components/saver/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@
},
"step": {
"user": {
"description": "Do you want to configure the Saver?",
"title": "Saver"
"description": "Do you want to configure the Saver?"
}
},
"title": "Saver"
}
}
}
6 changes: 2 additions & 4 deletions custom_components/saver/translations/pl.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@
},
"step": {
"user": {
"description": "Czy chcesz skonfigurowa\u0107 Saver?",
"title": "Saver"
"description": "Czy chcesz skonfigurowa\u0107 Saver?"
}
},
"title": "Saver"
}
}
}

0 comments on commit 24cbd34

Please sign in to comment.