const asArray = x => Array.isArray(x) ? x : [ x ]
Year: 2022
[SAPUI5] Get i18n texts
To simply get access to i18n texts, I useally add this helper function to my BaseController.js
// helper for direct access to the ResourceBundle getText() function
getText : function (sTextKey, aParamter) {
return this.getOwnerComponent().getModel("i18n").getResourceBundle().getText(sTextKey, aParamter)
}
Texts can then be read in every controller with
// i18n: objects=Amount of objects: {0}
this.getText("objects", [iLength])
[JavaScript] Get the Start and End of the Day in format yyyy-MM-ddTHH:mm:ss.SSSZ
const start = new Date()
const end = new Date()
start.setHours(0, 0, 0, 0)
end.setHours(23, 59, 59, 999)
console.log(start.toISOString())
console.log(end.toISOString())
[CAP] Login to CF using a bash script
Create your script file, make it executeable and add it to your .gitignore as it contains sensitive information:
touch login.sh
chmod +x login.sh
echo login.sh >> .gitignore
Open the file and paste the following:
#! /bin/bash
cf login <<!
myemail@mail.com
mypassword
1
!
With “1” you select your target space. Save your script and run it using:
./login.sh
After some time, it can happen that the default identity provider of the SAP BTP (SAP ID service) is asking for a password change. I don’t know exactly, but it seems to be every 90 days?!
The login process will fail with the following output:
$ ./scripts/login.sh
API endpoint: https://api.cf.eu10.hana.ondemand.com
Email: myemail@mail.com
Password:
Authenticating...
{"error":"invalid_grant","error_description":"User authentication failed: PASSWORD_CHANGE_REQUIRED"}
To change your password, just go to https://account.sap.com or https://accounts.sap.com/, and it should directly open the password change screen.
Update 06.09.2024: The login can now also be done by completely using the cf command.
cf login -a https://api.cf.eu10.hana.ondemand.com -o myOrg -s mySpace -u myEmail@mail.com -p myPassword
[CAP] Create and deploy bookshop sample app
Since CDS 5.9.2 this is the quickest way of creating and deploying the bookshop sample:
cds init bookshop
cd bookshop
cds add samples
cds add hana
cds add xsuaa
cds add mta
npm install
mbt build
cf deploy mta_archives/bookshop_1.0.0.mtar
[Home Assistant] Open window reminder
This automation is triggered when a window stays open for >10 minutes. It will then send a reminder every 10 minutes (max 6 times).
This post helped me to create this script.
alias: Open window reminder
description: ''
trigger:
- platform: state
entity_id: binary_sensor.lumi_lumi_sensor_magnet_aq2_xxx_on_off
from: 'off'
to: 'on'
for:
hours: 0
minutes: 10
seconds: 0
condition: []
action:
- repeat:
while:
- condition: state
entity_id: binary_sensor.lumi_lumi_sensor_magnet_aq2_xxx_on_off
state: 'on'
- condition: template
value_template: '{{ repeat.index <= 6 }}'
sequence:
- variables:
counter: '{{ repeat.index * 10 }}'
- service: telegram_bot.send_message
data:
message: Window is open for {{ counter }} minutes
- delay: '00:10:00'
mode: single
[ABAP] Include table fields in local type
Somehow I always forget the syntax for this….
TYPES: BEGIN OF ty_test.
INCLUDE TYPE z_table.
TYPES: my_new_field TYPE string,
END OF ty_test.
[Windows] Package Manager
https://just-install.github.io/
https://github.com/microsoft/winget-cli
For installing some basic software: https://ninite.com/
[Home Assistant] Control lights with multiple motion sensors
Create group of motion sensors in groups.yaml
https://www.home-assistant.io/integrations/group/
cellar_motion:
name: Cellar Presence
icon: mdi:motion-sensor
entities:
- binary_sensor.bewegungsmelder_xxx_ias_zone
- binary_sensor.bewegungsmelder_xxx_ias_zone
Next, if you have more than one light you’d like to control, create a group of lights in your configuration.yaml
https://www.home-assistant.io/integrations/light.group/
# Light Groups
light:
- platform: group
name: Cellar Lights
entities:
- light.ikea_of_sweden_tradfri_bulb_e27_ww_806lm_xxx_level_on_off
- light.ikea_of_sweden_tradfri_bulb_e27_ww_806lm_xxx_level_on_off
And finally use both in an automation
alias: My motion activated lights
description: Turn on a light when motion is detected.
trigger:
- platform: state
entity_id: group.cellar_motion
from: 'off'
to: 'on'
condition: []
action:
- service: light.turn_on
target:
entity_id: light.cellar_lights
data: {}
- wait_for_trigger:
platform: state
entity_id: group.cellar_motion
from: 'on'
to: 'off'
- delay: 120
- service: light.turn_off
target:
entity_id: light.cellar_lights
data: {}
mode: restart
max_exceeded: silent # https://www.home-assistant.io/docs/automation/modes/
[CAP] Get destination data using sap-cloud-sdk
https://sap.github.io/cloud-sdk/docs/js/features/connectivity/destination
const { getDestination } = require("@sap-cloud-sdk/connectivity")
const myDestination= await getDestination("myDestination")
if (myDestination === null) throw Error(`Destination "myDestination" not found`)
for (let key in myDestination) {
console.log(key, myDestination[key])
}